2

This is what the PHP manual said:

PDOStatement::fetchAll() returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name. An empty array is returned if there are zero results to fetch, or FALSE on failure. http://php.net/manual/de/pdostatement.fetchall.php

The thing is I get the FALSE returned always, if there is no other thing to fetch. (For example if I do an SQL UPDATE or INSERT).. Even if there was no problem and everything worked just fine.. What can I do about that? I want to notice if there went something wrong.

Thank you in advance :)

1 Answer 1

0

Are you checking explicitly for false? ===

If ($result === false) {
} 

The above is not the same as if (! $result) {... or if ($result == false) {... Those would equate to true if the value was zero or an empty array too.

You also might want to look at the ERRMODE setting for PDO. It can be set to throw exceptions for certain errors. You can then use try / catch blocks.

$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Sign up to request clarification or add additional context in comments.

1 Comment

Haha.. Im so stupid .. thank you. I did not the === only == :P I will mark your answer in 6 mins ^^

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.