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:
Hi Jani,
right, thank you.
If someone has a similar problem here my workaround to solve the
problem.
The goal is to compare an line in a sql Create Table Statement with the
actually value in the Database
<?php
$str = '`hereIsDefaultNULL` int(255) default NULL';
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) {
$fieldRow['Default'] = 'NULL';
}
$strToCompare= '`' . $fieldRow['Field'] . '` ' . $fieldRow['Type'] .
' default ' . $fieldRow['Default'];
if ($str == $strToCompare) {
echo 'OK';
}
}
?>
Previous Comments:
------------------------------------------------------------------------
[2009-11-12 10:43:49] [email protected]
But in PHP ('' == NULL) is true and ('' === NULL) isn't. :)
------------------------------------------------------------------------
[2009-11-12 10:27:50] w at lder dot de
Here the var_dump:
array(6) {
["Field"]=>
string(17) "hereIsDefaultNULL"
["Type"]=>
string(8) "int(255)"
["Null"]=>
string(3) "YES"
["Key"]=>
string(0) ""
["Default"]=>
NULL
["Extra"]=>
string(0) ""
}
array(6) {
["Field"]=>
string(19) "defaultEmptyvarchar"
["Type"]=>
string(12) "varchar(255)"
["Null"]=>
string(2) "NO"
["Key"]=>
string(0) ""
["Default"]=>
string(0) ""
["Extra"]=>
string(0) ""
}
Yes, I know that "'' == NULL (true)", but in mySQL :
mysql> SELECT '' IS NULL;
+------------+
| '' IS NULL |
+------------+
| 0 |
+------------+
mysql> SELECT NULL IS NULL;
+--------------+
| NULL IS NULL |
+--------------+
| 1 |
+--------------+
------------------------------------------------------------------------
[2009-11-12 10:06:28] [email protected]
Wait, ... I didn't get you changed table structure. Can you provide a
new var_dump but keep in mind:
[2009-11-12 11:05] <Jani_> '' == NULL (true), NULL == NULL (true).
Ulf
------------------------------------------------------------------------
[2009-11-12 10:00:16] [email protected]
Please, ask further question on how to use PHP elsewhere. There are no
bugs in this in either PHP or MySQL.
------------------------------------------------------------------------
[2009-11-12 09:33:02] [email protected]
Bogus
Why would one return NULL for meta data. NULL = undefined, "NULL" =
defined.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/50147
--
Edit this bug report at http://bugs.php.net/?id=50147&edit=1