get first insert id for multiple insert using pdo in mysql

Raj

I have multiple inserts using one query.

Now I am trying to get the first insert id instead of last insert id.

Just wondering if it is at all possible.

My code is

$sql = "INSERT INTO answers (quid, answer,catid,qstep,userid) VALUES (:quid,:answer,:catid,:qstep,:userid)";
$query = $this->db->prepare($sql);
foreach ( $insertData as $data )
{
    $query->execute($data);
}
Raphaël Malié
$sql = "INSERT INTO answers (quid, answer,catid,qstep,userid) VALUES (:quid,:answer,:catid,:qstep,:userid)";
$query = $this->db->prepare($sql);
$firstId = null;
foreach ( $insertData as $data )
{
    $query->execute($data);
    if (null === $firstId)
        $firstId = $this->db->lastInsertId();
}

?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysql insert into with multiple id from another table

From Dev

Converting MySql Insert To PDO

From Dev

PDO insert not inserting with multiple values

From Dev

PDO Insert multiple checkbox values in Mysql

From Dev

What is the best way to insert multiple rows in PHP PDO MYSQL?

From Dev

From Textarea to multiple value insert using PDO

From Dev

PHP PDO Multiple image INSERT

From Dev

mysql insert into two tables id from first

From Dev

How to do a multiple insert using LAST_INSERT_ID() MySQL?

From Dev

PDO Insert operation using PHP and MYSQL not working

From Dev

INSERT INTO array with MySQL and PDO

From Dev

mysql - insert in two tables using autogenerate key from first insert table without using LAST_INSERT_ID

From Dev

Insert Returning last ID with PDO

From Dev

Unable to insert into table using PDO in mysql

From Dev

Insert multiple values via PHP PDO into MySQL database

From Dev

Using mysql insert with implode in PDO

From Dev

keep first log_ID same as a parent_ID for every multiple insert query in mysql

From Dev

MYSQL Insert Where Not Exists with PDO

From Dev

Insert post with multiple tags in PDO

From Dev

How to get the insert ID after insert using the PDO transactino in php

From Dev

Confirm record INSERT with PDO and MySQL

From Dev

Pdo multiple row insert issue

From Dev

How to do a multiple insert using LAST_INSERT_ID() MySQL?

From Dev

Insert cookies and date pdo mysql

From Dev

Insert multiple rows using PHP PDO

From Dev

insert multiple ID in mysql row

From Dev

PHP, PDO, MySQL - Multiple INSERT vulnerable to injection?

From Dev

PDO insert BindParam mysql

From Dev

how to Insert multiple arrays with multiple rows into MySQL using PHP PDO

Related Related

HotTag

Archive