Created
December 10, 2015 23:52
-
-
Save mikedfunk/76e28f5159f630392d8f to your computer and use it in GitHub Desktop.
pdo insert assoc array
This file contains 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 | |
// @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