Re: [PHP] PDOStatement::rowCount() bug?

[email protected] (Nathan Nobbe)
Newsgroups php.general
Message-ID <[email protected]>
On Mon, Feb 22, 2010 at 7:50 PM, Paul M Foster <[email protected]>wrote:

> Using MySQL 5.075, PHP 5.25 on Debian unstable.
>
> Has anyone noticed, when issuing a PDOStatement::rowCount() call after a
> DELETE, UPDATE or INSERT, the return is uniformly zero, rather than the
> actual number of rows affected?
>

quick test shows rowCount() working in all 3 cases:

<?php
/**
* lets test a PDOStatement::rowCount() bug
* using an sqlite3 memory resident database
*/

try
{
$oPdo = new PDO('sqlite::memory:');
    $oPdo->query('CREATE TABLE TESTING (id INTEGER PRIMARY KEY, name
TEXT)');
    $oStmt = $oPdo->query("INSERT INTO TESTING (name) VALUES ('nate
dogg')");
    echo 'Num rows inserted: ' . $oStmt->rowCount() . PHP_EOL;
    $oStmt = $oPdo->query("UPDATE TESTING SET name = 'snoop dog' WHERE id =
1");
    echo "Num rows updated: " . $oStmt->rowCount() . PHP_EOL;
    $oStmt = $oPdo->query("DELETE FROM TESTING WHERE id = 1");
    echo "Num rows deleted: " . $oStmt->rowCount() . PHP_EOL;
}
catch(Exception $oE)
{
    die($oE->getMessage() . PHP_EOL);
}
?>

-------------
OUTPUT
-------------
Num rows inserted: 1
Num rows updated: 1
Num rows deleted: 1

-nathan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.