getting last inserted row id with PDO (not suitable result)
I have a problem with PDO::lastInsertId() method which doesn't return the id (primary key) of last inserted row, instead it returns another field which is a foreign key field. PHP code: $pdo = new PDO(...); $stmt = $pdo->prepare($sql); $stmt->bindParam(...); $stmt->bindParam(...); $stmt->execute(); $id = $pdo->lastInsertId(); // or $id = $pdo->lastInsertId('services_id_seq'); // I think 'services_id_seq' is not necessary in MySQL // both of them don't return the primary key of last inserted row echo 'last inserted id: ' . $id; MySQL Table structure: ... id int unsigned not null primary key