Mangala Edirisinghe
Mangala Edirisinghe

Reputation: 1111

How to use PDO::lastInsertId()?

$sql='INSERT INTO complaints(complaint_id) values(default)';
$db->query($sql,array());

//get newly added complaint_id

$complaint_id=$db->lastInsertId();

I used above code to get last insert ID from complaints table. But it gives an error like Fatal error: Call to undefined method EMMACore\Utils\DBConnection::lastInsertId() in /h... Can anybody tell me what is wrong in my application.Thanks.

Upvotes: 0

Views: 3068

Answers (2)

REFNTiE
REFNTiE

Reputation: 21

class db extends PDO

you can refer to this link PHP PDO Wrapper Class for example.

Upvotes: 0

xdazz
xdazz

Reputation: 160833

In most case, the PDO instance is a property of EMMACore\Utils\DBConnection, so check the source code and find it out.

Something like: $db->getDbh()->lastInsertId(); where getDbh (or something like that) returns the PDO instance.

Edit: After seeing your result of var_dump(), that is for sure.

Upvotes: 3

Related Questions