Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //---
- function placeholders($text, $count=0, $separator=","){
- $result = array();
- if($count > 0){
- for($x=0; $x<$count; $x++){
- $result[] = $text;
- }
- }
- return implode($separator, $result);
- }
- $pdo->beginTransaction() // also helps speed up your inserts
- $insert_values = array();
- foreach($data as $d){
- $question_marks[] = '(' . placeholders('?', sizeof($d)) . ')';
- $insert_values = array_merge($insert_values, array_values($d));
- }
- $sql = "INSERT INTO table (" . implode(",", array_keys($datafield) ) . ") "
- ."VALUES " . implode(',', $question_marks);
- $stmt = $pdo->prepare ($sql);
- try {
- $stmt->execute($insert_values);
- } catch (PDOException $e){
- echo $e->getMessage();
- }
- $pdo->commit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement