PHP 8.5.0 Alpha 4 available for testing

Voting

: nine minus six?
(Example: nine)

The Note You're Voting On

user at nospam dot example dot com
11 years ago
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!";
}

<< Back to user notes page

To Top