Last active
December 17, 2015 12:39
-
-
Save alancoleman/5611603 to your computer and use it in GitHub Desktop.
From an array to a db table using the PHP implode function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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