Jump to content

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]);
?>

 

I know the answer but I'll ask anyways:

You're calling execute() with two arguments. Two arrays. Why is that? Why do you believe they should be separate? And does the documentation support your belief?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.