PHP PDO fetch null?

When you connect to the database, you can set some attributes to control how PDO handles Nulls and Empty Strings when they are returned by the database query PDO::setAttribute (PDO::ATTR_ORACLE_NULLS, $option ) Where $option is one of the following: PDO::NULL_NATURAL: No conversion PDO::NULL_EMPTY_STRING: Empty stringis converted to NULL PDO::NULL_TO_STRING: NULL is converted to an empty string.

When you connect to the database, you can set some attributes to control how PDO handles Nulls and Empty Strings when they are returned by the database query PDO::setAttribute (PDO::ATTR_ORACLE_NULLS, $option ) Where $option is one of the following: PDO::NULL_NATURAL: No conversion. PDO::NULL_EMPTY_STRING: Empty stringis converted to NULL. PDO::NULL_TO_STRING: NULL is converted to an empty string.

Foreach($row as $r){ if($r->total_rating_votes == null){ //do something } Actually you might want to try: if($r->total_rating_votes == ""){/*do something*/} Because php might have converted the null value into an empty string, and then it's not actually null, it's "" Hope this helps!

Thanks for all of your answers. After a bit of experimentation this code solved my problem $this->total_rating_votes = $row'total_rating_votes'; if(!isset($this->total_rating_votes)) // this is now true if this record had a NULL value in the DB! { ... }.

If($row->column_name){ ...code...} I would check it like this. Or with the function empty() . EDIT: I think that the way you are doing you are not accesing well to the data and you are assigning an empty string to the $this->total_rating_votes, so that does not make it null.

I guess the way you fetch the data does not convert $row into an array, being $row an object.

Accessing the other values of $row however does work, e.g. $this->exercise_id = $row'exericse_id'; $this->author_id = $row'author_id'; $this->submisison = $row'submission'; $this->result = $row'result'; $this->submission_time = $row'submission_time'; all assign the correct values. – Jacob May 18 '10 at 9:40 -1 for the empty() suggestion, empty(0) === true, empty('0') === true, strlen() is a better alternative. – Alix Axel May 18 '10 at 10:12 1 @Alix Axel, yes you are right, empty would not be the most suitable function here.

– Dez May 18 '10 at 14:19.

I think that the way you are doing you are not accesing well to the data and you are assigning an empty string to the $this->total_rating_votes, so that does not make it null. I guess the way you fetch the data does not convert $row into an array, being $row an object.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions