From: Shawn McKenzie on
Shawn McKenzie wrote:
> First off, if the value is NULL in the database then in PHP it will be
> the string "NULL" and not a null value as far as I remember. Second,
> you cant use a function/method in empty(). Thirdly, the string "NULL"
> is not empty. I'm not sure what DB class you're using here or what the
> Fields() method actually returns. You should do a
> var_dump($rs->Fields(22)) to see. If it returns a string (especially
> "NULL"), then this or some variation should work:
>
> $q4 = $rs->Fields(22);
>
> if($q4 == "NULL"){
> $q4 = "";
> }
>
> If it returns an empty string or false then you may have nothing to do.
>
DOH! My bad. MySQL stores an empty value based upon the field type for
NULL. So if the field type is int then it sets it to 0 and if its
varchar, etc, it sets it to an empty string "". The MySQL functions
seem to return everything as a string, so for an int field it returns
the string "0", so:

$q4 = $rs->Fields(22);

if(empty($q4)){
$q4 = "";
}

But I'm not sure what benefit you get from this except that "0" is
changed to "".

--
Thanks!
-Shawn
http://www.spidean.com
From: Paul M Foster on
On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:

> $rs->Fields(22) equals a NULL in the database
>
> My Code:
>
> if(empty($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>
> Line 32 is the "if" line...
>
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>
> Line 196 is: <?php echo $q4;?>
>
> What am I doing wrong?
>
> Thanks!

Just a thought... do you really mean $rs->Fields(22) or do you mean
$rs->Fields[22]? The former is a function call and the latter is an
array variable.

Paul

--
Paul M. Foster
From: "David Stoltz" on
Paul,

This all started because when I try this:

<?php echo $rs->Fields(22);?>

It work fine, as long as there is a non-null value there, otherwise it
produces an error.

Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
sure if that matters....

But "echo $rs->Fields(22)" works perfectly for dumping values out of my
$rs recordset...that is, unless the value is NULL is the database - then
I get:

Catchable fatal error: Object of class variant could not be converted to
string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176


-----Original Message-----
From: Paul M Foster [mailto:paulf(a)quillandmouse.com]
Sent: Tuesday, August 25, 2009 4:39 PM
To: php-general(a)lists.php.net
Subject: Re: [PHP] How to output a NULL field?

On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:

> $rs->Fields(22) equals a NULL in the database
>
> My Code:
>
> if(empty($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> Produces this error:
> Fatal error: Can't use method return value in write context in
> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>
> Line 32 is the "if" line...
>
> If I switch the code to (using is_null):
> if(is_null($rs->Fields(22))){
> $q4 = "";
> }else{
> $q4 = $rs->Fields(22);
> }
>
> It produces this error:
> Catchable fatal error: Object of class variant could not be converted
to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>
> Line 196 is: <?php echo $q4;?>
>
> What am I doing wrong?
>
> Thanks!

Just a thought... do you really mean $rs->Fields(22) or do you mean
$rs->Fields[22]? The former is a function call and the latter is an
array variable.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

From: hack988 hack988 on
use is_null() check it

2009/8/26 David Stoltz <Dstoltz(a)shh.org>:
> Paul,
>
> This all started because when I try this:
>
> <?php echo $rs->Fields(22);?>
>
> It work fine, as long as there is a non-null value there, otherwise it
> produces an error.
>
> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> sure if that matters....
>
> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
> $rs recordset...that is, unless the value is NULL is the database - then
> I get:
>
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>
>
> -----Original Message-----
> From: Paul M Foster [mailto:paulf(a)quillandmouse.com]
> Sent: Tuesday, August 25, 2009 4:39 PM
> To: php-general(a)lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>
>> $rs->Fields(22) equals a NULL in the database
>>
>> My Code:
>>
>> if(empty($rs->Fields(22))){
>>       $q4 = "";
>> }else{
>>       $q4 = $rs->Fields(22);
>> }
>>
>> Produces this error:
>> Fatal error: Can't use method return value in write context in
>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>
>> Line 32 is the "if" line...
>>
>> If I switch the code to (using is_null):
>> if(is_null($rs->Fields(22))){
>>       $q4 = "";
>> }else{
>>       $q4 = $rs->Fields(22);
>> }
>>
>> It produces this error:
>> Catchable fatal error: Object of class variant could not be converted
> to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>
>> Line 196 is: <?php echo $q4;?>
>>
>> What am I doing wrong?
>>
>> Thanks!
>
> Just a thought... do you really mean $rs->Fields(22) or do you mean
> $rs->Fields[22]? The former is a function call and the latter is an
> array variable.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
From: "David Stoltz" on
I tried that -it's in the first part of my message


-----Original Message-----
From: hack988 hack988 [mailto:hack988(a)dev.htwap.com]
Sent: Wednesday, August 26, 2009 7:39 AM
To: David Stoltz
Cc: Paul M Foster; php-general(a)lists.php.net
Subject: Re: [PHP] How to output a NULL field?

use is_null() check it

2009/8/26 David Stoltz <Dstoltz(a)shh.org>:
> Paul,
>
> This all started because when I try this:
>
> <?php echo $rs->Fields(22);?>
>
> It work fine, as long as there is a non-null value there, otherwise it
> produces an error.
>
> Also, I'm working with a Microsoft SQL 2000 database, not MySQL....not
> sure if that matters....
>
> But "echo $rs->Fields(22)" works perfectly for dumping values out of my
> $rs recordset...that is, unless the value is NULL is the database - then
> I get:
>
> Catchable fatal error: Object of class variant could not be converted to
> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 176
>
>
> -----Original Message-----
> From: Paul M Foster [mailto:paulf(a)quillandmouse.com]
> Sent: Tuesday, August 25, 2009 4:39 PM
> To: php-general(a)lists.php.net
> Subject: Re: [PHP] How to output a NULL field?
>
> On Tue, Aug 25, 2009 at 02:00:04PM -0400, David Stoltz wrote:
>
>> $rs->Fields(22) equals a NULL in the database
>>
>> My Code:
>>
>> if(empty($rs->Fields(22))){
>>       $q4 = "";
>> }else{
>>       $q4 = $rs->Fields(22);
>> }
>>
>> Produces this error:
>> Fatal error: Can't use method return value in write context in
>> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32
>>
>> Line 32 is the "if" line...
>>
>> If I switch the code to (using is_null):
>> if(is_null($rs->Fields(22))){
>>       $q4 = "";
>> }else{
>>       $q4 = $rs->Fields(22);
>> }
>>
>> It produces this error:
>> Catchable fatal error: Object of class variant could not be converted
> to
>> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196
>>
>> Line 196 is: <?php echo $q4;?>
>>
>> What am I doing wrong?
>>
>> Thanks!
>
> Just a thought... do you really mean $rs->Fields(22) or do you mean
> $rs->Fields[22]? The former is a function call and the latter is an
> array variable.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>