PDOStatement::rowCount() bug?
PDOStatement::rowCount() bug?
am 23.02.2010 03:50:30 von Paul M Foster
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?
If so, is there a simple workaround?
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: PDOStatement::rowCount() bug?
am 23.02.2010 04:18:25 von Nathan Nobbe
--00504502cc03beb37d04803c006b
Content-Type: text/plain; charset=UTF-8
On Mon, Feb 22, 2010 at 7:50 PM, Paul M Foster 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:
/**
* 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
--00504502cc03beb37d04803c006b--
Re: PDOStatement::rowCount() bug?
am 23.02.2010 04:39:23 von Paul M Foster
On Mon, Feb 22, 2010 at 08:18:25PM -0700, Nathan Nobbe wrote:
> On Mon, Feb 22, 2010 at 7:50 PM, Paul M Foster 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:
>
>
> /**
> * lets test a PDOStatement::rowCount() bug
> * using an sqlite3 memory resident database
> */
Nifty, but you'll notice that I'm using MySQL, not SQLite3. And you
didn't mention which version PHP you're using.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: PDOStatement::rowCount() bug?
am 23.02.2010 04:48:24 von Nathan Nobbe
--00504502af98f3fefa04803c6bda
Content-Type: text/plain; charset=UTF-8
On Mon, Feb 22, 2010 at 8:39 PM, Paul M Foster wrote:
> On Mon, Feb 22, 2010 at 08:18:25PM -0700, Nathan Nobbe wrote:
>
> > On Mon, Feb 22, 2010 at 7:50 PM, Paul M Foster
> 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:
> >
> >
> > /**
> > * lets test a PDOStatement::rowCount() bug
> > * using an sqlite3 memory resident database
> > */
>
> Nifty, but you'll notice that I'm using MySQL, not SQLite3. And you
> didn't mention which version PHP you're using.
>
it had occurred to me that you may be using a diff db and that could have
something to do w/ it; however, ive just made a slight alteration to the
script and its working np w/ mysql:
-----------
sql
-----------
mysql> create database TESTING;
Query OK, 1 row affected (0.00 sec)
mysql> use TESTING;
Database changed
mysql> CREATE TABLE TESTING (
-> id INT NOT NULL AUTO_INCREMENT,
-> name CHAR(30) NOT NULL,
-> PRIMARY KEY (id)
-> );
-----------
php
-----------
/**
* lets test a PDOStatement::rowCount() bug
* using an sqlite3 database
*/
try
{
$oPdo = new PDO('mysql:host=192.168.56.101;dbname=TESTING', 'root', '');
$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);
}
?>
------------
version
------------
php version:
PHP 5.2.6-3ubuntu4.5 with Suhosin-Patch 0.9.6.2
mysql version:
Server version: 5.1.31-1ubuntu2
-nathan
--00504502af98f3fefa04803c6bda--
Re: PDOStatement::rowCount() bug?
am 23.02.2010 05:36:47 von Paul M Foster
On Mon, Feb 22, 2010 at 09:50:30PM -0500, Paul M Foster 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?
>
> If so, is there a simple workaround?
Update: MySQL 5.1.44.
rowCount() appears to return 0 only on deletes, not updates or inserts.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php