Jump to content

MYSQL NULL INT field returned to PHP as "0" string


gmckay

Recommended Posts

I have a table with a field defined as "`offer_limit_remaining` INT( 5 ) NULL".

I have rows where mySQL shows that the field contains NULL, however mysql_fetch_assoc() returns an array with the field containing "string: "0".

 

If I execute a SELECT field IS NULL in phpMyAdmin it returns the desired rows, so the table does contain NULLs.

 

How can I retrieve the field using "SELECT *" and detect that it contains NULL?

 

php 5.2.9

mySQL Server version: 5.1.33-community

MySQL client version: 5.0.51a

You will want to use is_null to test if the value is null, that is for PHP.

 

For the SQL check you can easily do:

SELECT * FROM table_name WHERE value IS NULL

 

Or

 

SELECT * FROM table_name WHERE value IS NOT Null

 

If that does not answer your question, let me know.

 

Example of the php code:

<?php
// mysql connect info:

$res = mysql_query("SELECT * FROM table_name");

while ($row = mysql_fetch_assoc($res)) {
if (is_null($row['field_name'])) {
	echo "It is null!";
}
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.