php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56339 PDO PgSQL no return for currval
Submitted: 2005-03-03 18:05 UTC Modified: 2005-05-16 13:01 UTC
From: dylan dot egan at optusnet dot com dot au Assigned:
Status: Not a bug Package: PDO_PGSQL (PECL)
PHP Version: 5.0.3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
45 + 44 = ?
Subscribe to this entry?

 
 [2005-03-03 18:05 UTC] dylan dot egan at optusnet dot com dot au
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] => )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-03 18:06 UTC] dylan dot egan at optusnet dot com dot au
Unsure, but may as well note. I am running PgSQL 8.0.1.
 [2005-05-13 13:39 UTC] wez@php.net
re-categorize.
 [2005-05-16 13:01 UTC] edink at emini dot dk
Preparing $stmt and executing $statement is usually not a good apporach :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC