$stmt->rowCount() always returns 0 on INSERT, UPDATE and DELETE
| Bug #33841 | PDO_SQLITE: $stmt->rowCount() always returns 0 on INSERT, UPDATE and DELETE | ||||
|---|---|---|---|---|---|
| Submitted: | 2005-07-23 23:23 UTC | Modified: | 2005-07-24 01:32 UTC | ||
| From: | people05 at sopic dot com | Assigned: | |||
| Status: | Closed | Package: | PDO related | ||
| PHP Version: | 5.1.0b3 | OS: | Debian GNU/Linux 3.1 | ||
| Private report: | No | CVE-ID: | None | ||
[2005-07-23 23:23 UTC] people05 at sopic dot com
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)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2005-07-23 23:38 UTC] iliaa@php.net
[2005-07-24 01:32 UTC] iliaa@php.net