1、在PHP中 使用mysqli扩充库对mysql 的dql操作复制代码 代码如下:

connect_error卡塔尔{ die(“连接战败”.$mysqli->connect_error卡塔尔(قطر‎; }
//2、操作数据库 $sql=”select *from user1″; //3、管理结果 $res
=$mysqli->query; //var_dump; //fetch_assoc fetch_array
fetch_object while($row=$res->fetch_row;/* foreach{ echo
‘–‘.$val; } echo ‘
‘;*/ } //4、关闭能源 $res->free;?>上面是面向进度的复制代码 代码如下:

2、在PHP中 使用mysqli扩大库对mysql 的dml操作复制代码 代码如下:

connect_error卡塔尔{ die(“连接退步”.$mysql->connect_errorState of Qatar; }
//扩张一条记下 //$sql=”insert into user1 (name,password,email,age卡塔尔values ,’lucy@163.com’,17卡塔尔”; //删除一条记下 //$sql=”delete from user1
where id =80″; //更新一条记下 $sql=”update user1 set age=20 where id=7″;
$res=$mysqli->query{ echo “操作失败”.$mysqli->error; }else{
if($mysqli->affected_新澳门31999 ,rows>0卡塔尔(قطر‎{ echo “成功”; }else{ echo
“未有行受影响”; } } //关闭财富 $mysqli->close(卡塔尔;?>3、实行包装
复制代码 代码如下: class SqlHelper{
private $mysqli; //这里先写死,未来写死的东西用叁个文件来安顿 private
static $host=”localhost”; private static $user=”root”; private static
$pwd=”root”; 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卡塔尔(قطر‎; } //设置字符集
$this->mysqli->query; } //dql operate function execute_dql{ $res
=$this->mysqli->query or die; return $res; } //dml operate
function execute_dml{ $res =$this->mysqli->query or die; if{
return 0;//失败 }else{ if($this->mysqli->affected_rows>0卡塔尔{
return 1;//成功 }else{ return 2;//未有行到影响 } } } }?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注