On trying to insert array of records, I am getting errors : 1. MySQL server has gone away 2. Error reading result set's header
Following are the details:
// DB2
$host1 = 'localhost';
$user1 = 'root';
$pass1 = '';
$db1 = 'my_db';
$conn1 = mysqli_connect($host1, $user1, $pass1, $db1);
....
...
...
...
//echo '<pre>'; print_r($countryArr); die;
$countryArr result :

$query = "INSERT INTO `cities` (`country_id`, `city`, `soft_delete`, `date_added`) VALUES " . implode(',', $countryArr);
mysqli_query($conn1, $query);
Error :

MySQL server has gone away may be due to exceeding limit on mysql packet size.
Check MySQL variable max_allowed_packet and try to increase it.
Step 1:
set_time_limit(0); // this will remove the time limit if any.
Step 2:
Also check ping to keep the connection alive, http://php.net/manual/en/mysqli.ping.php
Step 3
Try executing the inserts in batches. i.e Batch of 500 statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With