Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php pdo multiple insert

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(",", $datafields ) . ") VALUES " .
       implode(',', $question_marks);

$stmt = $pdo->prepare ($sql);
$stmt->execute($insert_values);
$pdo->commit();
Comment

PREVIOUS NEXT
Code Example
Php :: multidimensional session-array 
Php :: symony type request 
Php :: php artisan vendor:publish aborted 
Php :: Replace header template from plugin 
Php :: trying to change iframe location from javascript 
Php :: php get numer of items 
Php :: prevent cross site scripting php 
Php :: laravel command Retrieve a specific option 
Php :: change php platform of composer 
Php :: How to Create a Transient PHP wordpress 
Php :: Deutsch korrektur 
Php :: how to compare two strings ignoring accentuation in php 
Php :: create product model in laravel 
Php :: factorial program in php 
Php :: html css js php 
Php :: how to fetch data from database in php and display in pdf 
Php :: Regenerate session ID and remove all session data 
Php :: wc php get currency symbol 
Php :: int to string in php 
Php :: php parse_url array function 
Php :: how to create php message 2 
Php :: failed to delete data in mysqli using php 
Php :: laravel - How to concatenate URL and retrieve images from database in json format 
Php :: Symfony 5 - Customize Twig error templates 
Php :: if data come from foreach loop and if there are same value then sum of this same value and pass it to variable in php 
Php :: php season calculation 
Php :: what is post_class() 
Php :: split php 
Php :: array_shift in php 
Php :: wordpress programmatically change slug of media attachment site:wordpress.stackexchange.com 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =