#50147 [Bgs]: DEFAULT NULL Values in mysql_query('SHOW COLUMNS FROM `xx`');
| From: | w at lder dot de | Date: | Thu, 12 Nov 2009 09:08:41 +0000 |
| Subject: | #50147 [Bgs]: DEFAULT NULL Values in mysql_query('SHOW COLUMNS FROM `xx`'); | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144518@lists.php.net to get a copy of this message | ||
ID: 50147
User updated by: w at lder dot de
Reported By: w at lder dot de
Status: Bogus
Bug Type: MySQL related
Operating System: Linux 2.6.16.21-0.25-default
PHP Version: 5.2.11
New Comment:
OK, but how can I get the value NULL?
I think it is an difference between "NULL" and "".
Any idea?
Another Example:
<?php
/*
Mysql:
CREATE TABLE IF NOT EXISTS
test (
hereIsDefaultNULL int(255) default NULL,
defaultEmptyvarchar varchar(255) NOT NULL default ''
)
*/
mysql_connect('localhost','root','');
mysql_select_db('test');
$columns_res = mysql_query('SHOW COLUMNS FROM test');
while ($fieldRow = mysql_fetch_assoc($columns_res)) {
if ($fieldRow['Default'] == NULL) {
echo $fieldRow['Field'] . ' is NULL </br>';
}
}
?>
Expected result:
----------------
hereIsDefaultNULL is NULL
Actual result:
--------------
hereIsDefaultNULL is NULL
defaultEmptyvarchar is NULL
Previous Comments:
------------------------------------------------------------------------
[2009-11-12 08:38:18] jani@php.net
Replace print_r() with var_dump() and prepare for surprise.
------------------------------------------------------------------------
[2009-11-11 11:28:23] w at lder dot de
Here is the result:
mysql> SHOW COLUMNS FROM test;
+--------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+-------+
| hereIsDefaultNULL | int(255) | YES | | NULL | |
| defaultNULLvarchar | varchar(255) | YES | | NULL | |
+--------------------+--------------+------+-----+---------+-------+
------------------------------------------------------------------------
[2009-11-11 10:44:06] uw@php.net
ext/mysql returns whatever MySQL delivers. Please verify that the MySQL
prompt returns the result you want. If not, this is a MySQL bug not a
PHP bug.
Please run on the command line:
mysql -u<user> -p<password> <database>...
mysql> SHOW COLUMNS FROM <mytable>
------------------------------------------------------------------------
[2009-11-11 10:35:02] w at lder dot de
Description:
------------
The attached Code results a wrong result.
MySQL:
Server Version: 5.0.26
MySQL-Client-Version: 5.0.26
Reproduce code:
---------------
<?php
/*
MySQL:
CREATE TABLE IF NOT EXISTS test (
hereIsDefaultNULL int(255) default NULL,
defaultNULLvarchar varchar(255) default NULL
)
*/
mysql_connect('localhost','user','');
mysql_select_db('test');
$columns_res = mysql_query('SHOW COLUMNS FROM test');
while ($fieldRow = mysql_fetch_assoc($columns_res)) {
print_r($fieldRow) ;
}
?>
Expected result:
----------------
Array
(
[Field] => hereIsDefaultNULL
[Type] => int(255)
[Null] => YES
[Key] =>
[Default] => NULL
[Extra] =>
)
Array
(
[Field] => defaultNULLvarchar
[Type] => varchar(255)
[Null] => YES
[Key] =>
[Default] => NULL
[Extra] =>
)
Actual result:
--------------
Array
(
[Field] => hereIsDefaultNULL
[Type] => int(255)
[Null] => YES
[Key] =>
[Default] =>
[Extra] =>
)
Array
(
[Field] => defaultNULLvarchar
[Type] => varchar(255)
[Null] => YES
[Key] =>
[Default] =>
[Extra] =>
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50147&edit=1