|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-03-03 18:06 UTC] dylan dot egan at optusnet dot com dot au
[2005-05-13 13:39 UTC] wez@php.net
[2005-05-16 13:01 UTC] edink at emini dot dk
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 12:00:01 2025 UTC |
Description: ------------ Using lastInsertId with PgSQL just returns the OID which is not what we want. As all the tables are using sequences I thought I may as well get the currval of their sequence in the primary key field. Ran these queries through phpPgAdmin and it returns currval row with a value, but through PDO it returns nothing. I started using a simple PDO::query() call and then moved it into a full prepare/execute call. Reproduce code: --------------- $sql = "INSERT INTO table (bah, foo) VALUE ('woo', 'waz)"; $statement = $this->db->prepare($sql); if (!$statement->execute()) { throw new Exception("Failed query [$sql] with error [" . $this->db->errorInfo() . "]"); } $sql = "SELECT currval('".strtolower($idnr_seq)."')"; $stmt = $this->db->prepare($sql); if (!$statement->execute()) { throw new Exception("Failed query [$sql] with error [" . $this->db->errorInfo() . "]"); } print_r($stmt->fetch(PDO_FETCH_ASSOC)); Expected result: ---------------- Array ( [currval] => '27' ) Actual result: -------------- Array ( [currval] => )