[Kc] why doesn't this work - fetchrow_array
Teal
ironicface at earthlink.net
Thu Sep 20 10:01:16 PDT 2007
Daryl Fallin 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";
> }
>
I think $name is, because you have already declared it, defined.
What you need to test is not null or not false.
Teal
--
Five minutes of Silence,
Meditate. Breathe. Be Alive.
More information about the kc
mailing list