//mysqli 增强-批量执行sql 语句
//批量执行dql
//使用mysqli的mysqli::multi_query() 一次性添加3个用户
$mysqli =new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die ("连接失败".$mysqli->connect_error);
}
//注意分号
$sqls="insert into user1 (name,password,email,age) values('AAA',md5('AAA'),'AAA@hu.com',25);";
$sqls.="insert into user1 (name,password,email,age) values('BBB',md5('BBB'),'BBB@hu.com',25);";
$sqls.="insert into user1 (name,password,email,age) values('CCC',md5('CCC'),'CCC@hu.com',25);";
//批量执行dml 可以混合使用delete insert update 最好不要使用select
//$sqls.="update user1 set age=15 where id=1;";
//$sqls.="delete from user1 where id=10";
$res=$mysqli->multi_query($sqls);
if(!$res){
echo "操作失败".$mysqli->error;
}else{
echo "OK";
}
?>
|