This article to introduce to you the PHP mysqli bulk Execution of SQL statement program code, there is a need to know friends can refer to.
Mysqli enhanced-Bulk execution of SQL statements
The code is as follows |
Copy Code |
Mysqli enhanced-Bulk execution of SQL statements Batch Execution DQL Add 3 users at a time using Mysqli's Mysqli::multi_query ()
$mysqli =new mysqli ("localhost", "root", "root", "test"); if ($mysqli->connect_error) { Die ("Connection failed". $mysqli->connect_error); }
Note 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);";
Batch execution DML can be mixed with delete insert update 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
code as follows |
copy code |
Use Mysqli's mysqli::multi_query () to query the table for the contents of the Organization and table 1. Create a Mysqli object $mysqli =new mysqli ("localhost", "root", "root", "test"); if ($mysqli->connect_error) { Die ("Connection failed". $mysqli->connect_error); } 2. Batch query statements $sqls = "Select *from user1;"; $sqls. = "desc user1"; 3. Processing results If successful, there is at least one result set if ($res = $mysqli->multi_query ($sqls)) {
do{ Take out the first set of results $res = $mysqli->store_result (); while ($row = $res->fetch_row ()) { foreach ($row as $val) { Echo '--'. $val; } Echo ' '; } Free up memory in time $res->free (); Determine if there is a result set if ($mysqli->more_results ()) { echo "******** new result set *************** "; }else{ Break } }while ($mysqli->next_result ()); } 4. Close Resources $mysqli->close (); ?> |
http://www.bkjia.com/PHPjc/630720.html www.bkjia.com true http://www.bkjia.com/PHPjc/630720.html techarticle this article to introduce to you the PHP mysqli bulk Execution of SQL statement program code, there is a need to know friends can refer to. MYSQLI enhanced-Bulk Execute SQL statement code following copy code ...