php - Why does fetchColumn() always return 1?


I am confused as to why this always, even when I know it should be 0, returns 1.

function check_user_data($username, $password) { 
    global $db;
    $query = "SELECT COUNT(*) FROM users WHERE username='$username' AND password='$password'";
    $results = $db->query($query);
    $results = $results->fetchColumn();
    echo count($results);



because you are selecting a count in your query which returns a single number and then you are counting that single number withcount($results)




Why does fetchColumn() always return 1?

It doesn't.

Check your data and code.

People are also looking for solutions to the problem: php - Browse through calendar months with a href


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.