MySQL – Cannot Select All Data from Table in PHP

MySQL

$sql = $conn->prepare('SELECT * FROM users WHERE user_id != null');
if($sql->rowCount() > 0){
}
else{
echo "there are no users"
}

I want to select all data from a table however the code above does not work. It echoes/prints out "there are no users." No errors are shown too.

Best Answer

user_id != NULL

always fails. Instead, say

user_id IS NOT NULL

And you need to ->execute it.