Answers for "php insert array into mysql"

PHP
1

how to bulk insert array into sql php

$sql = array(); 
foreach( $data as $row ) {
    $sql[] = '("'.mysql_real_escape_string($row['text']).'", '.$row['category_id'].')';
}
mysql_query('INSERT INTO table (text, category) VALUES '.implode(',', $sql));
Posted by: Guest on March-11-2020
1

php insert array into mysql table

$matstring=implode("','",$matrix[1]);
mysql_query('INSERT INTO Australia (Price, Company, Days, Weight) VALUES ('$matstring')');
Posted by: Guest on August-04-2020
0

php insert array into mysql

if(is_array($records)){
 
    $DataArr = array();
    foreach($records as $row){
        $fieldVal1 = mysqli_real_escape_string($conn, $row[0]);
        $fieldVal2 = mysqli_real_escape_string($conn, $row[1]);
        $fieldVal3 = mysqli_real_escape_string($conn, $row[2]);
 
        $DataArr[] = "('$fieldVal1', '$fieldVal2', '$fieldVal3')";
    }
 
    $sql = "INSERT INTO programming_lang (field1, field2, field3) values ";
    $sql .= implode(',', $DataArr);
 
    mysqli_query($conn, $query);
}
Posted by: Guest on October-11-2021
0

php insert array into mysql

if(is_array($records)){
    foreach ($records as $row) {
        $fieldVal1 = mysqli_real_escape_string($conn, $row[0]);
        $fieldVal2 = mysqli_real_escape_string($conn, $row[1]);
        $fieldVal3 = mysqli_real_escape_string($conn, $row[2]);
 
        $query ="INSERT INTO programming_lang (field1, field2, field3) VALUES ( '". $fieldVal1."','".$fieldVal2."','".$fieldVal3."' )";
        mysqli_query($conn, $query);
    }
}
Posted by: Guest on October-11-2021

Browse Popular Code Answers by Language