php - MySqli multiple queries how to handle result faster way -
i have insert thousand of records. use msqli::multi_query()
in loop , want 'multi_query' block of n query (where 'n' parameter). first insert goes ok, second goes wrong because have manage result :
while($mysqli->more_results()) { $mysqli->next_result(); if($res = $mysqli->store_result()) // added closing bracket { $res->free(); } }
the problem chek slow.
question : how can optimize bulk insert makeing faster manage of result ?
if inserting in 1 table use batch mod in insert.
example:
insert table (field1,field2,field3) values (value1,value2,value3),(value4,value5,value6)
use for
or foreach
in php make query , use mysqli_query
. judging errors mentioned in comment section, violating ket restrictions meaning trying insert same value twice.
if inserting in different tables, can use multi_query
interface. prepare 1 query insert1;insert2;
, use multi_query
$con->multi_query($query); while (mysqli_more_results($con)) { mysqli_use_result($con); mysqli_next_result($con); }
Comments
Post a Comment