Skip to content

Instantly share code, notes, and snippets.

@nailton
Forked from anonymous/insertMulti.php
Last active August 29, 2015 14:05
Show Gist options
  • Save nailton/d00fb897c6a8c0d91b09 to your computer and use it in GitHub Desktop.
Save nailton/d00fb897c6a8c0d91b09 to your computer and use it in GitHub Desktop.
Instead of using a loop, you can combine the data into a single database query.
<?php
$userData = array();
foreach ($userList as $user) {
$userData[] = '("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
}
$query = 'INSERT INTO users (first_name,last_name) VALUES' . implode(',', $userData);
mysql_query($query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment