[Kc] why doesn't this work - fetchrow_array

Frank Wiles frank at wiles.org
Thu Sep 20 10:09:48 PDT 2007


On Thu, 20 Sep 2007 11:25:34 -0500
"Daryl Fallin" <darylvf at gmail.com> wrote:

> Even when the query is empty the If clause in the while loop will not
> print "name NOT defined"
> 
> I suspect this has something to do with fetchrow_array and using !
> defined() doesn't work.
> 
> ==========================================================
> 
> my $query = "select deviceip, devicename from (select * from
> admDevice where admDevice.devicename like \'%$_%\') as devi
>     ces, admSyslogSrc where devices.deviceId = admSyslogSrc.deviceId";
> 
> $sth = $dbh->prepare($query);
> 
> if( defined( $sth )) {
>     $sth->execute(  );
> }
> 
> while ( my ($hostint, $name) = $sth->fetchrow_array ) {
>     if ( !defined($name) ) {
>         print "name NOT defined";
>     }
> 

  To echo what Teal said, $name is 'defined', it just happens
  to be defined to an empty string ( aka NULL ) if the column
  is null.  

 -------------------------------------------------------
   Frank Wiles, Revolution Systems, LLC. 
     Personal : frank at wiles.org  http://www.wiles.org
     Work     : frank at revsys.com http://www.revsys.com 



More information about the kc mailing list