简体   繁体   中英

Getting Server Error 500 while inserting large amount of data in mysql database through php

I'm Getting Server Error 500 while inserting large amount of data in mysql database through php .

Actually I'm developing a scratch coupon scheme. And for that I've to create about a lac coupons at a time. But after about 14-16minutes it gives Server Error-500 which stops my execution and creates only about 16k-17k coupons.

I'm already increase the execution time, but it doesn't work-

ini_set('max_execution_time',0);
set_time_limit(0);

And used mysql insert batch query (creates block of 1000queries then run, and so on..) Something Like-

INSERT INTO scratch_coupon(coupon_id, coupon_code, gift_id) 
VALUES 
(NULL, '123456789', 5),
(NULL, '123456789', 5),
(NULL, '123456789', 5),
....and so on till 1000queries

Why is this is happening & what will be the solution ? Kindly assist. Thanks in advance!

Better use loop, it's more stable and reliable than sending single massive query.

Also, you can set your script to add let's say 5,000 rows, and you can set cron jobs to launch script every 5 minutes for 10 times. That will give you 50,000 rows in 50 minutes, but browser won't be needed.

this is a one-time process to fill the database, right? Then why not write the queries to a textfile first (name it for example createoupons.sql), and run the query using the commandline:

mysql -u yourusername -p yourpassword yourdatabase < createcoupons.sql

this is the safest way to import large amounts of data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM