Jump to content

php pdo multiple rows insertion to mysql problem?


shams

Recommended Posts

I search the internet to find the solution from multiple row insertion there was many codes but i cannot use for my query this is a piece of code, please help how to execute for multiple rows insertion:

<?php
$host = 'localhost';
$db   = 'test';
$user = 'user';
$pass = '';
$charset = 'utf8mb4';

$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
$pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass, $options);
///////
$cat_id=$_POST['cat-id'];
$subcategory=$_POST['subcategory'];
$subcat2=$_POST['subcat2'];
$subcategory2=$_POST['subcategory2'];
$sql = "INSERT INTO subcategory (cat_id, subcategory, subcat2) VALUES (?,?,?),(?,?,?)";
$stmt= $pdo->prepare($sql);
$stmt->execute([$cat_id, $subcategory, $subcat2],[$cat_id, $subcategory2, $subcat2]);
?>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.