gmckay Posted December 21, 2009 Share Posted December 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185934-mysql-null-int-field-returned-to-php-as-0-string/ Share on other sites More sharing options...
premiso Posted December 21, 2009 Share Posted December 21, 2009 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!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185934-mysql-null-int-field-returned-to-php-as-0-string/#findComment-981879 Share on other sites More sharing options...
gmckay Posted December 21, 2009 Author Share Posted December 21, 2009 SOLVED. Thanks, it's a little confusing as, although NULL, the field is shown as string "0" in the debugger, and resolves to 0 when used in php. Quote Link to comment https://forums.phpfreaks.com/topic/185934-mysql-null-int-field-returned-to-php-as-0-string/#findComment-981885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.