RE: [PHP] Re: How to output a NULL field?

2009-08-27 Thread David Stoltz
You're a genius - that works!


-Original Message-
From: Bastien Koert [mailto:phps...@gmail.com] 
Sent: Wednesday, August 26, 2009 2:02 PM
To: Andrew Ballard
Cc: Shawn McKenzie; php-general@lists.php.net; David Stoltz
Subject: Re: [PHP] Re: How to output a NULL field?


One option then, might be to format the result with SQL using a CASE
WHEN THEN statement or ISNULL / IFNULL to set it to empty string

-- 

Bastien

Cat, the other other white meat

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



Re: [PHP] Re: How to output a NULL field?

2009-08-27 Thread Martin Scotta
On Thu, Aug 27, 2009 at 9:37 AM, David Stoltz dsto...@shh.org wrote:

 You're a genius - that works!


 -Original Message-
 From: Bastien Koert [mailto:phps...@gmail.com]
 Sent: Wednesday, August 26, 2009 2:02 PM
 To: Andrew Ballard
 Cc: Shawn McKenzie; php-general@lists.php.net; David Stoltz
 Subject: Re: [PHP] Re: How to output a NULL field?


 One option then, might be to format the result with SQL using a CASE
 WHEN THEN statement or ISNULL / IFNULL to set it to empty string

 --

 Bastien

 Cat, the other other white meat

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


Let me do this simple question... is your Sql Server legal? Then use it.

If not, why don't you migrate to an open source alternative? there are a lot
of DB you can use, and if you use an open source alternative then it's
legal, that's mean you, or your client, do not have to pay for use it.

I'm not going to say *that* DB is better that *this* other, this is a matter
of taste.

-- 
Martin Scotta


Re: [PHP] Re: How to output a NULL field?

2009-08-26 Thread Bastien Koert
On Wed, Aug 26, 2009 at 12:06 PM, Andrew Ballardaball...@gmail.com wrote:
 On Tue, Aug 25, 2009 at 3:22 PM, Shawn McKenzienos...@mckenzies.net 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.

 I've not seen this happen. I've found, depending on the database and
 the data access library used to interface with it that NULL usually
 comes back as either the PHP NULL value or an empty string.

 Andrew

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



One option then, might be to format the result with SQL using a CASE
WHEN THEN statement or ISNULL / IFNULL to set it to empty string

-- 

Bastien

Cat, the other other white meat

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



[PHP] Re: How to output a NULL field?

2009-08-25 Thread Shawn McKenzie
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!

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.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Re: How to output a NULL field?

2009-08-25 Thread Shawn McKenzie
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

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