<?php
class SqlHelper{
private $mysqli;
private static $host="localhost";
private static $user="root";
private static $pwd="1234";
private static $db="test";
public function __construct(){
//完成初始化的任务
$this->mysqli=new
mysqli(self::$host,self::$user,self::$pwd,self::$db);
if($this->mysqli->connect_error){
die("连接失败".$this->mysqli->connect_error);
}
//设置访问数据库的字符集
//这句话的作用是保证php是以utf-8来操作mysql
$this->mysqli->query("set names utf8");
}
public function execute_dql(){
$res=$this->mysqli->query($sql) or die("操作dql".$this->mysqli->error);
return $res;
}
public function execute_dml($sql){
$res=$this->mysqli->query($sql) or die("操作dql".$this->mysqli->error);
if(!$res){
return 0;//表示失败
}else{
if($this->mysqli->affected_rows>0){
return 1;//表示成功
}else{
return 2; //表示没有行受到影响
}
}
}
}
?>
class SqlHelper{
private $mysqli;
private static $host="localhost";
private static $user="root";
private static $pwd="1234";
private static $db="test";
public function __construct(){
//完成初始化的任务
$this->mysqli=new
mysqli(self::$host,self::$user,self::$pwd,self::$db);
if($this->mysqli->connect_error){
die("连接失败".$this->mysqli->connect_error);
}
//设置访问数据库的字符集
//这句话的作用是保证php是以utf-8来操作mysql
$this->mysqli->query("set names utf8");
}
public function execute_dql(){
$res=$this->mysqli->query($sql) or die("操作dql".$this->mysqli->error);
return $res;
}
public function execute_dml($sql){
$res=$this->mysqli->query($sql) or die("操作dql".$this->mysqli->error);
if(!$res){
return 0;//表示失败
}else{
if($this->mysqli->affected_rows>0){
return 1;//表示成功
}else{
return 2; //表示没有行受到影响
}
}
}
}
?>