php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35391 PDO::exec does not return number of affected rows
Submitted: 2005-11-25 13:40 UTC Modified: 2005-11-25 13:56 UTC
From: chris at x98 dot org Assigned:
Status: Closed Package: MySQL related
PHP Version: 5.1.0 OS: Windows XP SP 2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris at x98 dot org
New email:
PHP Version: OS:

 

 [2005-11-25 13:40 UTC] chris at x98 dot org
Description:
------------
According to the docs, PDO::exec should return the number of rows affected by the INSERT/DELETE/... statement. In my setup (WinXPSP2/Apache 2.0.55/PHP 5.1.0/mysql 4.1.15-nt), int(0) is returned instead always.

Reproduce code:
---------------
// table test has two columns (id and value)
 
$db = new PDO('mysql:host=localhost;dbname=test', 'xxxxx', 'xxxxx');
 
for ($i=1;$i<5;$i++) {
	$count = $db->exec("INSERT INTO TEST (id, value) VALUES ($i, 1)");
 	var_dump($count);
}
 
$count = $db->exec("DELETE FROM test WHERE id>0");
var_dump($count);


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

(assuming table test was empty before)

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-25 13:54 UTC] chris at x98 dot org
Additional Note: if PDO::Statement with rowCount() function is used instead, the number of affected rows gets returned as expected: 

 for ($i=1;$i<5;$i++) {
 	$stm = $db->prepare("INSERT INTO TEST (id, value) VALUES ($i, 1)");
 	$stm->execute();
 	var_dump($stm->rowCount());
 }
 
 $stm = $db->prepare("DELETE FROM test WHERE id>0");
 $stm->execute();
 var_dump($stm->rowCount());

returns 

int(1) int(1) int(1) int(1) int(4)
 [2005-11-25 13:56 UTC] tony2001@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC