计算机网络/计算机科学与应用/系统/运维/开发

mysqli扩展

配置:

php.ini 中 extension=php_mysqli.dll,支持预准备语句


1、面向对象

语法:

mysqli([string host [,string username[,string pswd,[string dbname[,int port,[string socket]]]]]]);

$mysqli = new mysqli("localhost","root","root","exer");

或者:

$mysqli = new mysqli();
$mysqli->connect("localhost","root","root","exer");

关闭服务器:

$mysqli->close();


2、面向过程

$conn = mysqli_connect("localhost","root","root","exer");

关闭服务器:

mysqli_close($conn);

3、预准备语句

绑定结果和绑定参数

绑定结果:

<?php 
 $mysqli=new mysql("localhost","root","root","exer");
 $mysqli->set_charset('utf8');
 $sql = "select * from message";
 // 预准备语句查询
 $result = $mysqli->prepare($sql);
 // 执行预准备
 $result ->execute();
 // 用自定义变量绑定结果
 $result->bind_result($id,$title,$name);
 while($result->fetch()){
    echo "id";
 }
 // 关闭预准备语句
 $result->close();
 // 关闭数据库连接
 $mysqli->close();



好的习惯,排名第一的是:自律;排名第二的是:终身学习;排名第三的是:保持运动。拥有这三种习惯,美好人生垂手可得。

评论

^