Skip to content
Advertisement

PHP PDO::FETCH_ASSOC returns false

In this code fetch(PDO::FETCH_ASSOC) retunrs false even if $row>0.
I couldn’t find why this is happening.

Here session is not set as $member is null.

JavaScript

I’ve read many and stackoverflow questions and forums but couldn’t find a solution for this.

JavaScript

Advertisement

Answer

You are using fetch instead of rowCount:

JavaScript

From PDO::fetch():

Fetches the next row from a result set.

The return value of this function on success depends on the fetch type. In all cases, FALSE is returned on failure.

I’d assume here that only 1 user can exist in the database with those credentials, when you first execute the $rows = $result->fetch(PDO::FETCH_NUM);, the resultset cursor is moved over to the next row-set (which doesn’t exist, as there was only a single row).

Therefore, you get a false in the later call.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement