|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-11 10:30 UTC] shadda at gmail dot com
Description:
------------
I'm using PostgreSQL 8.1.2, on Debian Sid. In my database, I have a table with a RULE on inserts...
CREATE RULE test_rule AS
ON INSERT TO test_table
DO ALSO
SELECT NEW.id;
When a new row is inserted to this table, it returns the ID (currval) of the new row. This works from PSQL, DBI (perl), and JDBC, aswell as the standard Pgsql extension in PHP.
From PDO, however, when calling PDOStatement::Fetch() after an insert, only an empty array is returned, and not the resultset I was expecting.
Reproduce code:
---------------
create table test_table ( id serial primary key );
create rule test_rule as on insert to test_table do also select new.id;
postgres@Xanadu:/$ php -r '
$db = new PDO("pgsql:host=localhost;user=xoom;password=1914;dbname=general");
$q = $db->query("insert into foo default values");
var_dump($q->fetch());
'
Expected result:
----------------
array(2) {
[0]=>
string(2) "10"
["id"]=>
string(2) "10"
}
Actual result:
--------------
array(0) {
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 05:00:01 2025 UTC |
The issue related to native prepared statements not describing that magical result set. Workaround: $stmt = $db->prepare("insert into test_table default values", array( PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => true)); $stmt->execute(); print_r($stmt->fetchAll());