I have the following SQLite query, but I’m not sure how to check for no rows being returned, other than by doing another query. Can anyone help?
$query = 'SELECT
id, name, email, comment, datetime, ipaddress, approved
FROM guestbook
WHERE approved=0
ORDER BY id DESC;';
$result = $db->query($query);
Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
That means the SQLite driver isnt implementing the number of affected rows, and you’ll have to resort to the more draconian loop-and-count. (Or fetchall and size the array. Same thing.)