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

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();



人生在世,不如意事十之八九;人生的滋味,哪怕是酸甜或苦辣,也要靠自己去品。人活一口气:气质看一个人的过去,气度看一个人的未来

评论

^