Home >Backend Development >PHP Tutorial >php mysqli executes sql statement program code in batches_PHP tutorial
This article will introduce to you the PHP mysqli batch execution of sql statement program code. Friends who need to know more can refer to it.
mysqli enhancement-batch execution of sql statements
The code is as follows | Copy code | ||||
<🎜> //mysqli enhancement-batch execution of sql statements<🎜> <🎜> //Batch execution of dql //Use mysqli's mysqli::multi_query() to add 3 users at one time $mysqli =new MySQLi("localhost","root","root","test"); If($mysqli->connect_error){ die ("Connection failed".$mysqli->connect_error); } //Note the semicolon $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);"; //To execute dml in batches, you can use delete, insert, and update together. It is best not to use 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 "Operation failed".$mysqli->error; }else{ echo "OK"; } ?> |
2. Batch query
The code is as follows
|
Copy code | ||||
//Use mysqli's mysqli::multi_query() to query the organization and contents of the table at one time