Recent Topics

1 May 25, 2008 23:58    

Like, if a database table has something like

my_field_name varchar(32) default NULL,

in it and I don't add a value to my_field_name then I do something like

if( my_field_name == '' )

will it be true or false?

If false how would I default the database table to something that is nothing, or how would I make the if look for NULL on the right side?

Oh wait a second. I think I should just use

my_field_name varchar(32) NOT NULL default '',

and pretend that makes me happy.

2 May 26, 2008 00:33

NULL is an entity in php also, so you can test on NULL

if ($foo == NULL )
{
 ...

3 May 26, 2008 01:08

Weirdly enough, so is blonde

<?php
echo 'bugger me '.( empty( $blonde ) ? 'I should have known better' : 'it doesn\'t work, no surprises there then :' );
?>

¥

5 May 26, 2008 01:28

Thanks blueyed (and Afwas and ¥åßßå)! I rarely think about === or !== because I'm pretty simple, but yeah lots of the details pages at php.net say to use it for this or that or the other thing.

Cool. So I can leave the table defaulting to NULL and still check it with either == NULL or == '' and expect basically the same results. The first is obviously better so that is what a smart person would do.


Form is loading...