The best way to check it with prepare
and fetchColumn
SELECT COUNT(*) statement with the same predicates as your intended
SELECT statement, then use PDOStatement::fetchColumn() to retrieve the
number of rows that will be returned.
$sql = "SELECT COUNT(*) FROM users WHERE username = ?";// use `COUNT(*)`
$result = $db->prepare($sql);
$result->execute(array('administrator'));
echo $result->fetchColumn() ? 'true' : 'false';