Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Last active December 17, 2015 12:39
Show Gist options
  • Save alancoleman/5611603 to your computer and use it in GitHub Desktop.
Save alancoleman/5611603 to your computer and use it in GitHub Desktop.
From an array to a db table using the PHP implode function
<?php
$dbh = dbconnect(); // open db conn
$tblupdatedetailsql = array(); // define $tblupdatedetailsql array
foreach ($adGroups as $adGroup) { // populate new sql array using content array
$tblupdatedetailsql[] = '('.$tblupdateid.', 0, "'.mysql_real_escape_string($adGroup->name).'")';
}
// insert in the db using the implode function and the array
$insert = "INSERT INTO tbl (id,type,desc) VALUES".implode(',', $tblupdatedetailsql);
$statement = $dbh->prepare($insert); //prepare
$statement->execute(); // execute
unset($tblupdatedetailsql); // unset $tblupdatedetailsql.
$dbh = null; // close db conn
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment