#33841 [NEW]: PDO_SQLITE: $stmt->rowCount() always returns 0 on INSERT, UPDATE and DELETE

From: Date: Sat, 23 Jul 2005 21:23:26 +0000
Subject: #33841 [NEW]: PDO_SQLITE: $stmt->rowCount() always returns 0 on INSERT, UPDATE and DELETE
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82365@lists.php.net to get a copy of this message
From:             people05 at sopic dot com
Operating system: Debian GNU/Linux 3.1
PHP version:      5.1.0b3
PHP Bug Type:     PDO related
Bug description:  PDO_SQLITE: $stmt->rowCount() always returns 0 on INSERT, UPDATE and DELETE

Description:
------------
I'm not sure if it's a error in the docs or a PDO bug. http://
www.php.net/manual/en/function.pdostatement-rowcount.php says, 
"PDOStatement::rowCount() returns the number of rows affected 
by the last DELETE, INSERT, or UPDATE statement executed by 
the corresponding PDOStatement object." When I execute my code 
sample, $stmt->rowCount() always returns int(0) instead of the 
expected int(1).

Some lines down the page, the docs say that rowCount() doesn't 
work on a SELECT with the most databases, but there's no 
exception for INSERT, UPDATE or DELETE.

Reproduce code:
---------------
<?php

try {
	$db = new PDO("sqlite:/tmp/sqlite.sdb");
	$stmt = $db->prepare("INSERT INTO test ( name ) VALUES ( :name ) ");
	$stmt->bindParam(':name', $name);
	$name = 'Andreas';
	$stmt->execute();
	var_dump($stmt->rowCount());
	$last_insert_id = $db->lastInsertId();
	$stmt = $db->prepare("UPDATE test SET name = :name ");
	$stmt->bindParam(':name', $name);
	$name = 'Peter';
	$stmt->execute();
	var_dump($stmt->rowCount());
	$stmt = $db->prepare("DELETE FROM test");
	$stmt->execute();
	var_dump($stmt->rowCount());
} catch (Exception $e) {
	echo $e->getMessage();	
}

?>

Expected result:
----------------
int(1)
int(1)
int(1)

Actual result:
--------------
int(0)
int(0)
int(0)

-- 
Edit bug report at http://bugs.php.net/?id=33841&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33841&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33841&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33841&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33841&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33841&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33841&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33841&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33841&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33841&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33841&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=33841&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=33841&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33841&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33841&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33841&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33841&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33841&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33841&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33841&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33841&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#82365) next »