mysqli扩展库是mysql扩展库的改进版本,在mysql扩展库的基础上提高了稳定性和效率,mysqli扩展库有两套东西,一套就是面向过程的mysqli另一套是面向对象的mysqli。操作方式大体和mysql扩展库大体一致,这次还是先抽取出来一个操作mysql的工具类,和调用的类。
相关mysql视频教程推荐:《mysql教程》
1.mysqli扩展库操作数据库工具类
conn=new mysqli($this->host, $this->username, $this->password,$this->dbname) or die($this->conn->connect_error);
}
//查询
public function query($sql){
$all= $this->conn->query($sql);
return $all;
}
//插入,修改,删除
public function otherOperate($sql){
if($this->conn->query($sql)){
if($this->conn->affected_rows>0){
return "OK";
}else{
return "ERROOR";
}
}
}
public function close(){
$this->conn->close();
}
}
?>2.下面是具体的调用工具类的代码
立即学习“PHP免费学习笔记(深入)”;
query($sql);
while($row=$result->fetch_assoc()){
echo "$row[stuName]"."";
}
$result->free();
$util->close();*/
$sql="update m_student set stuName='杨幂' where id=3";
$util=new DBUtil();
$result=$util->otherOperate($sql);
echo $result;
$util->close();
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号