get one column
From: Ing. Branislav Gerzo (2ge_at_2ge.us)
Date: 01/28/05
- Next message: Thilo Planz: "Re: get one column"
- Previous message: Michael A Chase tech: "Re: how to retrieve data from postgresql database"
- Next in thread: Thilo Planz: "Re: get one column"
- Reply: Thilo Planz: "Re: get one column"
- Reply: Michael A Chase tech: "Re: get one column"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Jan 2005 09:55:53 +0100 To: dbi-users@perl.org
Hi all!
I have subroutine, that checks, if I already have in DB specified row:
sub image_exist {
my ($id, $date) = @_; #id is _always_ number
my $sth = $mydbh->prepare_cached("select ID from pic where id = ?");
$sth->execute($id);
my $rows = $sth->fetchall_arrayref();
if ( @$rows[0] ) {
print "$id exist\n";
} else {
print "$id not exist\n";
}
}
I am pretty sure, this can be done better. Also I am curious about
this - when I change statement to:
my $sth = $mydbh->prepare_cached("select ID from pic where id = $id");
$sth->execute();
I get after some results:
Use of uninitialized value in concatenation (.) or string at D:\cygwin\home\Admi
nistrator\thumbs\insert_pic.pl line 81.
DBD::mysql::st execute failed: You have an error in your SQL syntax; check the m
anual that corresponds to your MySQL server version for the right syntax to use
near '' at line 1 at D:\cygwin\home\Administrator\thumbs\insert_pic.pl line 82.
Hm, strange...
I am using AS perl v5.8.6
-- Brano
- Next message: Thilo Planz: "Re: get one column"
- Previous message: Michael A Chase tech: "Re: how to retrieve data from postgresql database"
- Next in thread: Thilo Planz: "Re: get one column"
- Reply: Thilo Planz: "Re: get one column"
- Reply: Michael A Chase tech: "Re: get one column"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|