I have to do a lot of insert in my DB, importing data from xml. Now, if I open and close the connection in the loop, the script works but crashes for max connection number, and if I use the following code, it execute just one time the mysqli_multi_query.
I just need to know, how to maintain the connection to execute a new multi query in the loop.
$xml = simplexml_load_file('demo.xml');
$mysqli =new mysqli($servername, $username, $password, $dbname);
foreach($xml->datas as $data) {
$sql="INSERT IGNORE INTO table1 (hobby) values ('".$data->child74."');";
$sql.="INSERT IGNORE INTO table2 (pizza, spaghetti) values ('".$data->child55."', '".$data->child52."');";
// a lot more insert...
mysqli_multi_query($mysqli,$sql);
}
mysqli_close($mysqli);
"or it is type ?mysqli_multi_query?