I am new to working with MySQL and am looking for some guidance with this problem.
I am entering lots of data into a MySQL table.
I have set it up using this format so the VALUES
are in a loop and the INSERT
part only happens once:
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
I have read SO post: How to do a batch insert in MySQL
I am trying to insert up to 160,000 rows of data. My php script seems to get stuck after a short time and only 6499 rows of data get inserted to the table.
I think I am having a problem with the Max_Allowed_Packet
I am using hosting with iPage and I am on a shared server. I've asked iPage about Max_Allowed_Packet
but I'm told this can only be increased if on a Virtual Private Server (VPS). This project is not worth paying for a private server at this time.
I'm looking for coding ways to insert all this data whilst on a shared server.
Is submitting 1000 lines at a time an option?
I'm not sure if this is a good solution, I'm grateful for any ideas.
Here is the section of the code where the data is inserted:
// prepare first part of the query (before values)
$query = " INSERT INTO `Events_testing2` (
`eventID`,
`location`,
`date`,
`barcode`,
`runner`,
`time`,
`Run Points`,
`Volunteer Points`,
`Gender`,
`Gender pos`
) VALUES ";
//loop the runner array
for($x=0;$x<count($array_runner); $x++){
$query_values[] = "(' ','$location','$date','$array_barcode[$x]','$array_runner[$x]','$array_time[$x]','$array_score[$x]','','$array_gender[$x]','$array_gender_pos[$x]')";
}
// put the code together to insert to the DB
$queryInsertUser=mysqli_query($link,$query.implode(',',$query_values));