54. mysqli 扩展库
来源:互联网 发布:印度红色走廊 知乎 编辑:程序博客网 时间:2024/05/17 07:01
mysqli 扩展库
在 php.ini 总启用 mysqli扩展库:
extension = php_mysqli.dll
<?phpheader('Content-Type:text/html;charset=utf8');//mysqli 操作 mysql 数据库(面向对象风格)//1.创建MySQLi对象$mysqli = new MySQLi('localhost','root','123456','test');if($mysqli->connect_error){ die("连接失败" . $mysqli->connect_error);}else{ echo "连接成功";}//2.操作数据库(发送sql)$sql = "select * from user1";$result = $mysqli->query($sql);//3.处理结果while($row = $result->fetch_row()){ foreach($row as $k=>$v){ echo $v . "---"; } echo "<br/>";}//4.释放资源$result->free();//5.关闭连接$mysqli->close();
dml 操作:
<?phpheader('Content-Type:text/html;charset=utf8');//mysqli 操作 mysql 数据库(面向对象风格)//1.创建MySQLi对象$mysqli = new MySQLi('localhost','root','123456','test');if($mysqli->connect_error){ die("连接失败" . $mysqli->connect_error);}else{ echo "连接成功";}//2.操作数据库(发送sql)$sql = "insert into user1 (name,password,email,age) values('小宏',md5('aaa'),'xiaohong@11.com',8)";//$sql = "delete from user1 where id=10";//$sql = "update user1 set age=50 where id=1";$result = $mysqli->query($sql);//3.处理结果if(!$result){ echo "操作失败" . $mysqli->error;}else{ //看看有多少行记录影响 if($mysqli->affected_rows>0){ echo "执行Ok"; }else{ echo "没有行受到影响"; }}//5.关闭连接$mysqli->close();
工具类:
SqlHelper.php:<?phpclass SqlHelper{ private $mysqli; private static $host="localhost"; private static $user='root'; private static $pwd='123456'; 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是以utf8的方式来操作我们的数据库 $this->mysqli->query("set names utf8"); } public function execute_dql($sql) { $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;//表示没有行受到影响 } } }}
<?phpheader('Content-Type:text/html;charset=utf8');require_once 'SqlHelper.php';$sqlHelper = new SqlHelper();$sql = "insert into user1 (name,password,email,age) values('小宏',md5('aaa'),'xiaohong@11.com',8)";$res = $sqlHelper->execute_dml($sql);var_dump($res);
0 0
- 54. mysqli 扩展库
- mysqli扩展库操作
- MySQLi扩展库
- MySQLi扩展库
- php之mysqli扩展库
- 55. mysqli 扩展库(2)
- 56. mysqli 扩展库(3)
- 57. mysqli 扩展库(4)
- mysql扩展库mysqli讲解!!!!!
- Mysqli扩展库的总结
- 使用mysqli扩展库 预处理技术 mysqli stmt
- 运用MySQLI扩展库的预处理功能...
- mysqli扩展库的预处理机制
- php中mysql mysqli pdo扩展库
- php mysqli扩展库的使用
- mysqli扩展php的mysqli扩展
- mysql扩展库和mysqli扩展库的比较
- Php的mysqli扩展
- 因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系
- Hadoop与Spark的安装
- 【UML】-九种图之协作图
- 根据进程名称查找进程
- Android ListView等列表设置空布局
- 54. mysqli 扩展库
- Anorm, simple SQL data access
- Mysql函数:Last_insert_id()语法讲解
- C++异步调用Future机制漫谈
- ssh安全配置
- 搜索框制作(笔记)
- C++API设计
- Using "RDP Encoder Mirror Driver" to Capture Screen
- 根据进程名或者ID称关闭进程