SAD Posted December 29, 2019 Share Posted December 29, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309762-timeout-in-php/ Share on other sites More sharing options...
gw1500se Posted December 29, 2019 Share Posted December 29, 2019 You can either set_time_limit in the script which applies to only that script or max_execution_time in your php.ini file which will apply to all scripts. Quote Link to comment https://forums.phpfreaks.com/topic/309762-timeout-in-php/#findComment-1572964 Share on other sites More sharing options...
Barand Posted December 29, 2019 Share Posted December 29, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309762-timeout-in-php/#findComment-1572965 Share on other sites More sharing options...
SAD Posted December 29, 2019 Author Share Posted December 29, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309762-timeout-in-php/#findComment-1572966 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.