PHP mysqli 增強(qiáng) 批量執(zhí)行sql 語句的實現(xiàn)代碼建站知
導(dǎo)讀:1建站知識mysqli 增強(qiáng)-批量執(zhí)行sql 語句 復(fù)制代碼 代碼如下: ?php //mysqli 增強(qiáng)-批量執(zhí)行sql 語句 //批量執(zhí)行dql //使用mysqliseo網(wǎng)站排名優(yōu)化軟件網(wǎng)站優(yōu)化seo培訓(xùn)。
mysqli 增強(qiáng)-批量執(zhí)行sql 語句
復(fù)制代碼 代碼如下:
<?php
//mysqli 增強(qiáng)-批量執(zhí)行sql 語句
//批量執(zhí)行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',網(wǎng)站建設(shè)25);";
//批量執(zhí)行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";
}
?>
2、批量查詢
復(fù)制代碼 代碼如下:
<?php
//使用mysqli的mysqli::multi_query() 網(wǎng)站seo優(yōu)化一次性查詢表的機(jī)構(gòu)和表中的內(nèi)容
//1、創(chuàng)建mysqli對象
$mysqli=new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("連接失敗".$mysqli->connect_error);
}
//2、批量查詢語句
$sqls="select *from user1;";
$sqls.="desc user1";
//3、處理結(jié)果
//如果成功,至少有一個結(jié)果集
if($reseo網(wǎng)站優(yōu)化培訓(xùn)s=$mysqli->multi_query($sqls)){
do{
//取出第一個結(jié)果集
$res=$mysqli->store_result();
while($row=$res->fetch_row()){
foreach($row as $val){
echo '--'.$val;
}
echo '<br/>';
}
//及時釋放內(nèi)存
$res->free();
//判斷是否還有結(jié)果集
if($mysqli->more_results()){
echo "********新的結(jié)果集***************<br/>";
}else{
break;
}
}while($mysqli->next_result());
}
//4、關(guān)閉資源
$mysqli->close();
?>
相關(guān)seo網(wǎng)站排名優(yōu)化軟件網(wǎng)站優(yōu)化seo培訓(xùn)。
聲明: 本文由我的SEOUC技術(shù)文章主頁發(fā)布于:2023-05-24 ,文章PHP mysqli 增強(qiáng) 批量執(zhí)行sql 語句的實現(xiàn)代碼建站知主要講述批量,語句,PHP mysqli 增強(qiáng) 批量執(zhí)行sql 語句網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請保留鏈接: http://www.bifwcx.com/article/web_6768.html
為你推薦與PHP mysqli 增強(qiáng) 批量執(zhí)行sql 語句的實現(xiàn)代碼建站知相關(guān)的文章
-
通王TWCMS 2.0.3網(wǎng)站模板程序下載
(126)人喜歡 2024-01-15 -
Windows官方原版在哪里下載
(175)人喜歡 2024-01-15 -
WordPress網(wǎng)站模板發(fā)帖標(biāo)題顏色設(shè)置
(131)人喜歡 2024-01-07 -
修改discuz論壇帖子標(biāo)題80字符的長度限制
(249)人喜歡 2024-01-07 -
wordpress程序調(diào)用不帶超鏈接的Tag標(biāo)簽
(234)人喜歡 2024-01-05 -
網(wǎng)站在不同時期需調(diào)整內(nèi)容更新的方向
(112)人喜歡 2023-08-12