Last active
July 28, 2021 02:59
-
-
Save mllvzeth/be5dce2bee914c423bd0b7ffca68da00 to your computer and use it in GitHub Desktop.
simplified automatic PDO INSERT SQL time saver ⌛ by @Rami_jamleh; with revision by @Clair_Shaw
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 | |
| /** | |
| * @Rami jamleh - http://php.net/manual/en/pdostatement.execute.php#111823 | |
| * @Clair_Shaw(Revision) - http://php.net/manual/en/pdostatement.execute.php#116901 | |
| * simplified $placeholder form | |
| **/ | |
| $data = ['a'=>'foo','b'=>'bar']; | |
| $keys = array_keys($data); | |
| $fields = '`'.implode('`, `',$keys).'`'; | |
| //$placeholder = substr(str_repeat('?,',count($keys),0,-1)); | |
| $placeholder = substr(str_repeat('?,',count($keys)),0,-1); | |
| $pdo->prepare("INSERT INTO `baz`($fields) VALUES($placeholder)")->execute(array_values($data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment