Skip to content

Instantly share code, notes, and snippets.

@kursusHC
Created April 11, 2015 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kursusHC/6ea14a00b6e82c224797 to your computer and use it in GitHub Desktop.
Save kursusHC/6ea14a00b6e82c224797 to your computer and use it in GitHub Desktop.
PDO insert array into MySQL (array keys same as field names)
$prep = array();
foreach($insData as $k => $v ) {
$prep[':'.$k] = $v;
}
$sth = $db->prepare("INSERT INTO table ( " . implode(', ',array_keys($insData)) . ") VALUES (" . implode(', ',array_keys($prep)) . ")");
$res = $sth->execute($prep);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment