WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making my first plugin and I need to import about 31,000 records from a sql file into the wpdb when the plugin first gets installed by the user, but it is only importing about half of them only, around 18,000 records.

In the install function I have these lines to INSERT the data:

$sql = file_get_contents(ABSPATH . 'wp-content/plugins/plugin-name/sql.sql');

Within the sql file I have this:

<? $sql = "CREATE TABLE IF NOT EXISTS $table_name (
`book` int(11) default NULL, 
`chapter` int(11) default NULL,
`verse` int(11) default NULL, 
`text` text

(4, 6, 27, 'text string here'),
(4, 6, 28, 'text string here'),
(4, 6, 29, 'text string here'),
(4, 6, 30, 'text string here');
"; ?>

I have tried using wpdb->query and wpdb->prepare but it is still not working. I have tried so many different ways and spent lots of hours trying to figure it out but it doesn't work.

What can I do so that I can import 100% of the records when the plugin gets installed?

Thank you in advance.

share|improve this question
I'll guess that there's no way to reliably import 31,000 rows of data on all server setups in one go, you'll run into execution time errors, which is possibly what's happening to you. Check error logs. I'd suggest exploring ways to do this asynchronously in batches. – Milo Jun 10 '13 at 16:44
I got it! If anyone would later one need this, here it is. code ... require_once(ABSPATH . 'wp-content/plugins/plugin_name/sql.php'); require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); code The sql.php looks like: code $sql .= $wpdb->query($wpdb->prepare("CREATE TABLE IF NOT EXISTS $table_name ( col1 int(11) default NULL, col2 text ) ENGINE=MyISAM DEFAULT CHARSET=utf8")); $sql2 .= $wpdb->query($wpdb->prepare("INSERT INTO $table_name(col1, col2) VALUES (1, 1, 1, 'text string.'), (1, 1, 2, 'text string.'), (1, 1, 3, 'text string.')")); code – Arlo Jun 10 '13 at 18:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.