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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dylan dot egan at optusnet dot com dot au
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 16:01:28 2024 UTC