Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get id of updated row in PDO

Tags:

php

mysql

pdo

I updated a row in database using PDO.

 $stmt = $db->prepare("UPDATE product SET price=? WHERE seller=?");
             $stmt->execute(array(456,"Apple"));

This didn't worked for me

$updated_id = $db->lastInsertId();

How can i get the id of that updated row.

like image 981
Brainy Prb Avatar asked Nov 01 '22 16:11

Brainy Prb


1 Answers

Best you can do is use PDO::rowCount() to get the number of rows affected. Remember, your update statement may not update only one, so, there is no way to just get a single id.

like image 50
brian Avatar answered Nov 08 '22 04:11

brian