note 80041 added to function.PDOStatement-rowCount
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 26 Dec 2007 12:10:33 +0000 |
| Subject: | note 80041 added to function.PDOStatement-rowCount | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134016@lists.php.net to get a copy of this message | ||
The rowCount method does not seem to work with pdo_sqlite, maybe because it will not support
forward-only cursors:
<?php
error_reporting(E_ALL+E_NOTICE);
$dsn = 'sqlite::memory:';
$pdo = new PDO($dsn);
$pdo->exec('CREATE TABLE foo(id varchar(11) NOT NULL, PRIMARY KEY(id))');
$pdo->exec("INSERT INTO foo(id) VALUES ('ffs')");
$sqlGet = 'SELECT * FROM foo WHERE id=:id';
$stmt = $pdo->prepare($sqlGet);
$id = 'ffs';
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$stmt->execute();
var_dump($stmt->rowCount(), count($stmt->fetchAll()));
?>
which outputs: 0 1
http://php.net/manual/en/function.sqlite-num-rows.php
says sqlite_num_rows() cannot be used on unbuffered results; the explanation to the failure of the
rowCount() method is probably along the same lines.
The workaround would be to use the count() function on a fetched result, but it might not be as
efficient.
----
Server IP: 194.246.101.61
Probable Submitter: 82.255.112.223
----
Manual Page -- http://www.php.net/manual/en/function.PDOStatement-rowCount.php
Edit -- https://master.php.net/note/edit/80041
Del: integrated -- https://master.php.net/note/delete/80041/integrated
Del: useless -- https://master.php.net/note/delete/80041/useless
Del: bad code -- https://master.php.net/note/delete/80041/bad+code
Del: spam -- https://master.php.net/note/delete/80041/spam
Del: non-english -- https://master.php.net/note/delete/80041/non-english
Del: in docs -- https://master.php.net/note/delete/80041/in+docs
Del: other reasons-- https://master.php.net/note/delete/80041
Reject -- https://master.php.net/note/reject/80041
Search -- https://master.php.net/manage/user-notes.php