note 113133 added to pdostatement.rowcount
| From: | user at nospam dot example dot com | Date: | Tue, 03 Sep 2013 18:49:59 +0000 |
| Subject: | note 113133 added to pdostatement.rowcount | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196153@lists.php.net to get a copy of this message | ||
MySQL does not seem to return anything in rowCount for a select statement, but you can easily and
efficiently get the row count as follows:
class db extends PDO {
public function last_row_count() {
return $this->query("SELECT FOUND_ROWS()")->fetchColumn();
}
}
$myDb = new db('mysql:host=myhost;dbname=mydb', 'login', 'password' );
Then, after running your query:
if ( $myDb->last_row_count() == 0 ) {
echo "Do something!";
}
----
Server IP: 69.147.83.199
Probable Submitter: 76.246.64.133
----
Manual Page -- http://php.net/manual/en/pdostatement.rowcount.php
Edit -- https://master.php.net/note/edit/113133
Del: integrated -- https://master.php.net/note/delete/113133/integrated
Del: useless -- https://master.php.net/note/delete/113133/useless
Del: bad code -- https://master.php.net/note/delete/113133/bad+code
Del: spam -- https://master.php.net/note/delete/113133/spam
Del: non-english -- https://master.php.net/note/delete/113133/non-english
Del: in docs -- https://master.php.net/note/delete/113133/in+docs
Del: other reasons-- https://master.php.net/note/delete/113133
Reject -- https://master.php.net/note/reject/113133
Search -- https://master.php.net/manage/user-notes.php