For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > August 2006 > DB_DataObject test for null









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DB_DataObject test for null
Chris Domigan

2006-08-23, 9:58 pm


Hi everyone,

I'm having trouble working out how to test for a null value using
DB_DataObject.

If a field is set to NULL, the corresponding property in the data object is
"", ie blank and not "null". Obviously it's very handy to be able to
differentiate between an empty string and null.

I've tried using the special sql casts that DB_DataObject supports, but this
only lets me set null values, which I can already do anyway using
$object->property = "null".

Any help would be appreciated :)

Chris
--
View this message in context: http://www.nabble.com/DB_DataObject...6.html#a5956787
Sent from the Pear - General forum at Nabble.com.
Alan Knowles

2006-08-24, 7:58 am

Due to limitations in the PHP variable model, you cant reliably do this...

However - you can do something like

$do->selectAs("(mytestcol IS NULL) AS mytestcolIsNull");
......
if ($do->mytestcolIsNull) {......

Regards
Alan

Chris Domigan wrote:
> Hi everyone,
>
> I'm having trouble working out how to test for a null value using
> DB_DataObject.
>
> If a field is set to NULL, the corresponding property in the data object is
> "", ie blank and not "null". Obviously it's very handy to be able to
> differentiate between an empty string and null.
>
> I've tried using the special sql casts that DB_DataObject supports, but this
> only lets me set null values, which I can already do anyway using
> $object->property = "null".
>
> Any help would be appreciated :)
>
> Chris

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com