* Kwok Siang > OS: win XP > mysql : 3.23.54-max > > can someone help me with this unexplainable question. > > i create this in the mysql database, > > CREATE TABLE `foo` ( > `num` int(4) unsigned zerofill NOT NULL default > '0000' > ) TYPE=MyISAM; > > after that, i tried to insert a blank data into it,
hm... "a blank data"...? The field is defined as an integer, and as NOT NULL. > INSERT INTO foo set num=''; > *(there's nothing between the quotes) This is the same as "INSERT INTO foo set num=0;" because a string used in a numeric context is converted to a number: '0' -> 0, '1' -> 1, '2' -> 2 and so on. Any string not containing digits is converted to 0: mysql> select ''=0,'a'=0,'1'=0,'0'=0; +------+-------+-------+-------+ | ''=0 | 'a'=0 | '1'=0 | '0'=0 | +------+-------+-------+-------+ | 1 | 1 | 0 | 1 | +------+-------+-------+-------+ 1 row in set (0.00 sec) > In the database it display 4 zeros which is 0000, but > when i perform a search of an empty string like this, > > SELECT * FROM foo WHERE num=''; Same problem here, you are actually searching for num=0. Try this to verify: SELECT * FROM foo WHERE num='whatever'; > The result was 0000, by right it will hav an empty > set. > How could this happen? Please help You should not use the datatype INTEGER if you wish to store strings[1] in the column. Take a look in the manual at the many different datatypes supported by mysql: <URL: http://www.mysql.com/doc/en/Column_types.html > [1] an empty string is still a string... :) -- Roger --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php