配置:
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();