<?php
//multi_querry一次性添加几个数据。。。
//1、创建mysqli对象
$mysqli=new mysqli("127.0.0.1","root","password","testdb");
//验证是否连接成功
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//2、操作数据库(发送sql语句) 一次添加多条数据
$sqls="insert into users (name,password,email,age) values("zhangsan","123456","zhangsan@163.com","15");";
$sqls.="insert into users (name,password,email,age) values("lisi","123456","lisi@163.com","23");";
$sqls.="insert into users (name,password,email,age) values("wangwu","123456","wangwu@163.com","37");";
//3multi_query返回一个布尔值 其中只要有一个查询失败则返回flase
$b=$mysqli->multi_query($sqls);
if($b){
echo"执行失败".mysqli->error;
}else{
echo"ok";
}
//4关闭资源
mysqli->close();
?>
mysqli扩展库操作mysql数据库 multi_query一次添加多个数据
最新推荐文章于 2024-02-29 15:34:27 发布