I am using PHP lite to search for a matching row like this...
$count = $db->exec("SELECT * FROM users WHERE userid = '34534fgr'");
echo $count;
But my count is returning 1 every time, even when the value does not exist.
Am I searching incorrectly?
Am I searching incorrectly?
yup. protip: when debugging, use var_dump
instead of echo
, it would help you see the issue here, because it would print bool(true);
instead of int(1)
or string("1")
, because PDO::exec() returns a boolean.
here's how to do what you tried to do:
$count = $db->query("SELECT COUNT(*) FROM users WHERE userid = '34534fgr'",PDO::FETCH_NUM)->fetch()[0];