Edit report at https://bugs.php.net/bug.php?id=61267&edit=1
ID: 61267 Updated by: cataphr...@php.net Reported by: ben dot pineau at gmail dot com Summary: pdo_pgsql's PDO::exec() returns the number of SELECTed rows on postgresql >= 9. -Status: Open +Status: Closed Type: Bug Package: PDO related Operating System: all PHP Version: Irrelevant -Assigned To: +Assigned To: cataphract Block user comment: N Private report: N New Comment: This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2012-03-08 08:52:19] cataphr...@php.net Automatic comment from SVN on behalf of cataphract Revision: http://svn.php.net/viewvc/?view=revision&revision=324014 Log: - Fixed bug #61267: pdo_pgsql's PDO::exec() returns the number of SELECTed rows on postgresql >= 9 ------------------------------------------------------------------------ [2012-03-03 13:54:09] ben dot pineau at gmail dot com Description: ------------ After executing a SELECT statement, PDO::exec() -using the pdo_pgsql driver and running against a PostgreSQL server older than 9.0- will always returns 0, as does the pdo_mysql and pdo_sqlite drivers. ie. this is the exepected behaviour (though to be precise, the PDO::exec() documentation stipulate : "PDO::exec() does not return results from a SELECT statement."). But when executed against a PostgreSQL >= 9.0 server, this very same php client and select statement will return the number of selected rows. This is due to a server side change in how PostgreSQL servers answers to libpqs's PQcmdTuples() commands (PQcmdTuples() being used as the PDO::exec() return value, via pdo_pgsql pgsql_handle_doer() function). This server-side change is visible by comparing this command's documentation for different PostgreSQL versions : http://www.postgresql.org/docs/8.4/interactive/libpq-exec.html#LIBPQ-EXEC- SELECT-INFO http://www.postgresql.org/docs/9.1/interactive/libpq-exec.html#LIBPQ-EXEC- SELECT-INFO See also the bug in pg_affected_rows https://bugs.php.net/bug.php?id=61266 I just reported. The attached patch does check whether the PDO::exec() param was a (successful) DML statement before using PQcmdTuples() to return the number of affected rows. Also attached, a test script for PHP's unit test infrastructure. Test script: --------------- // Bugs on PostgreSQL >= 9.0 server (but ok on previous versions) $dbh = new PDO("pgsql:dbname=postgres ;host=localhost", 'postgres'); var_dump($dbh->exec("SELECT * from generate_series(1, 42);")); Expected result: ---------------- int(0) Actual result: -------------- int(42) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61267&edit=1