<?php
//批量執行時可以混合執行delete,insert,update語句,但最好不要使用select
$mysqli=new mysqli('localhost','root','root','test');
if($mysqli->connect_error)
die($mysqli->connect_error);
$mysqli->query("set names utf8");
$sql="insert into user1 (name,password,email,age) values ('傻子1',md5('asd'),'[email protected]','34');";
$sql.="insert into user1 (name,password,email,age) values ('傻子2',md5('attyyd'),'[email protected]','24');";
$sql.="insert into user1 (name,password,email,age) values ('傻子3',md5('3546d'),'[email protected]','46')";
$b=$mysqli->multi_query($sql);
if(!$b)
echo "失敗".$mysqli->error;
else
echo "成功";
$sqls="delete from user1 where id=59;";
$sqls.="delete from user1 where id=60;";
$sqls.="delete from user1 where id=61";
$res=$mysqli->multi_query($sqls);
if(!$res==0)
echo $mysqli->error;
else
echo "成功2";
$mysqli->close();
?>
<?php
$mysqli=new mysqli('localhost','root','root','test');
if($mysqli->connect_error)
$mysqli->query("set names utf8");
$sqls="select * from user1;";
$sqls.="select * from words;";
$sqls.="desc user1";
//處理結果與關閉資源
if($res=$mysqli->multi_query($sqls))//如果成功則至少有乙個結果集
echo "
"; }
$result->free();//釋放結果集
if(!$mysqli->more_results()) //判斷後面還有無結果集
break;
}while($mysqli->next_result());
}$mysqli->close();
?>
mysqli 批量執行多條語句
可以一次性的執行多個操作或取回多個結果集。例項 mysqli new mysqli localhost root 111111 test check connection if mysqli connect errno multi query執行乙個或多個針對資料庫的查詢。多個查詢用分號進行分隔。q...
Oracle批量執行SQL語句
1.在plsql之類的工具中把語句塊寫在begin end之間,如 begin insert into table values insert into table values insert into table values insert into table values end 記住在end...
Oracle批量執行SQL語句
1.在plsql之類的工具中把語句塊寫在begin end之間,如 begin insert into table values insert into table values insert into table values insert into table values end 記住在end...