Jump to content

Timeout in PHP


SAD

Recommended Posts

I am trying to transfer a large amount of data from a text file exported from a Microsoft Access database into a MSQL database.  I have written a script in PHP to open the text file, read a line at a time, sort out the data for insertion into a new table and then insert the data into the table in the MSQL database.  This works perfectly for 3 or 100+ records, so the fundamentals appear to be solid.  The problem starts when I try to do all the records - about 33,500.  I get:

Fatal error: Maximum execution time of 30 seconds exceeded in C:\DATA\HTMLServedDocs\MusicIndex\MusicImport.php on line 40.

Line 40 is the database write: $result = mysqli_query($dbc, $query);

I'm not sure if the root of the error is the Web Server, the Database or something else.  I am using the Abyss server, which while it is a bit clunky it is appropriate for the application.  

Does anyone have any ideas how to get around this problem.  I could split the data up into smaller files but that is not ideal.  

Link to comment
Share on other sites

The fastest way, by far, is to export from Access into a CSV file then use a LOAD DATA INFILE command in SQL to load the csv into the database table.

The next fastest way is to take advantage of MySQL's multiple insert queries EG

INSERT INTO mytablename (col1, col2, col3) 
VALUES
(1, 'aaa', 'bbbb'),
(2, 'bbb', 'cccc'),
(3, 'ccc', 'dddd'),

. . .

(998, 'ddd', 'eeee'),
(999, 'eee', 'ffff');

and load several hundred records with each insert.

The slowest way is to iterate through a file, inserting one record at a time.

Link to comment
Share on other sites

Many thanks for the help.

I was using bulk transfer, but completely forgot about PHP timeouts.  Must by holiday fog - or too much Christmas pudding!

After playing with the import text file and tidying up a few dodgy records it has now imported in to MYSQL and works as expected. 

The Access database was inherited, not very well set up and the data entry had been a bit random.  Now the data is cleaned everything is working as expected.

If the data had been tidy and better formatted i might have used the direct transfer into the database.

Anyway all done now.

Regards

Shane

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.