[thelist] Setting a MySQL value to NULL using PHP

Hans Zaunere zaunere at yahoo.com
Wed May 1 10:13:01 CDT 2002


--- rudy <r937 at interlog.com> wrote:
> >... in everything else [NULL] is an evil monster
> > waiting to rip your head off and cause you a lot of pain.
>
> oh dear
>
> if you are having pain, it is because you are letting the programming
> language master you, rather than you mastering it
>
> try using the COALESCE function to ensure that no nulls ever come
> back from
> the database to your (inadequate) programming language to be
> misinterpreted

It's not a matter of the programming language, but rather the
programmer.  In loosely typed languages it's too easy to forget about
type checking.  C doesn't let this happen (or if it does, you're
program will generally seg fault, rather than hum along producing
incorrect results).

>
> > Use simply 0, 1, or negatives if the situation fits.
>
> respectfully, no, do not do this
>
> "if the situation fits?" -- don't bother doing AVG() when you have a
> bunch
> of 0's in there which really should be nulls
>
> some situations *require* nulls for accuracy -- i.e. data integrity

Exactly why I stated "if the situation fits."  When dealing with
ints/floats/etc, NULL is useful, and sometimes mandatory.  However,
again, with loosely typed languages this distinction can easily fall
apart and special care must be taken in these languages.

>
> with all due respect, you should embrace nulls, not run away from
> them

I love NULLs... but just in C (and in MySQL for joining purposes -
another reason to set your columns NOT NULL).

Hans Z.
New York PHP
http://nyphp.org



__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com



More information about the thelist mailing list