Skip to content

Instantly share code, notes, and snippets.

@mikedfunk
Created December 10, 2015 23:52
Show Gist options
  • Save mikedfunk/76e28f5159f630392d8f to your computer and use it in GitHub Desktop.
Save mikedfunk/76e28f5159f630392d8f to your computer and use it in GitHub Desktop.
pdo insert assoc array
<?php
// @link http://stackoverflow.com/questions/13507496/pdo-php-insert-into-db-from-an-associative-array
$keys = array_keys($a);
$sql = "INSERT INTO user (".implode(", ",$keys).") \n";
$sql .= "VALUES ( :".implode(", :",$keys).")";
$q = $this->dbConnection->prepare($sql);
return $q->execute($a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment