Confirm record INSERT with PDO and MySQL

user1032531

The following will echo $response of 1 if there is no error regardless whether a record was inserted.

I read PDO mysql: How to know if insert was successful, however, it just describes if the query was unsuccessful presumably doe to an error.

How can I confirm whether a record was inserted or not?

<?php
$sql='INSERT INTO t3(id,data) SELECT id,data FROM t2 WHERE id=?';
$stmt=db::db()->prepare($sql);
$response=$stmt->execute(array(123));
echo($response);
?>
Dan

PDO::rowCount will return the number of affected rows.

So you could: echo $stmt->rowCount();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using PDO and failing to insert a record

From Dev

Using PDO and failing to insert a record

From Dev

Converting MySql Insert To PDO

From Dev

INSERT INTO array with MySQL and PDO

From Dev

PDO insert BindParam mysql

From Dev

Insert record PHP/PDO throwing error

From Dev

MYSQL Insert Where Not Exists with PDO

From Dev

Using mysql insert with implode in PDO

From Dev

Insert cookies and date pdo mysql

From Dev

Duplicate record in mysql after INSERT

From Dev

MySQL INSERT record using SELECT

From Dev

INSERT mySQL record if conditions are met

From Dev

mysql query insert duplicate record

From Dev

Updating database record with PHP/PDO and mySQL

From Dev

mysql pdo update record using LEFT JOIN

From Dev

How to tell if PDO MySQL INSERT was successful with IGNORE

From Dev

Insert JSON decoded data into mysql with PDO

From Dev

Can't INSERT into mysql via PDO

From Dev

PDO Insert multiple checkbox values in Mysql

From Dev

PDO Insert operation using PHP and MYSQL not working

From Dev

PHP; PDO; MySQL; INSERT query not taking input

From Dev

PHP; PDO; MySQL INSERT query with drop down

From Dev

Insert form value into mysql database with pdo

From Dev

Unable to insert into table using PDO in mysql

From Dev

Trying to insert pdo bound parameters into mysql database

From Dev

Mysql - conditional insert query with select and PDO

From Dev

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

From Dev

PDO MYSQL insert statement not working (no error given)

From Dev

PDO insert into MySQL Database not working with another PDO query