[Changed quoting - I find the "append whole message at bottom" quoting style *extremely* unreadable]
On 2002-03-07 08:39:41 -0500, Vorce, Tim (T.) wrote: > > From: Peter J. Holzer [mailto:[EMAIL PROTECTED]] > > Subject: Re: Using IN with prepare clause > > > > > From: Andy Crichton [mailto:[EMAIL PROTECTED]] > > > Subject: Using IN with prepare clause > > > > > > I wish to do something to the effect of: > > > > > > $stmt="SELECT fruit FROM tree WHERE fruit in (@fruits)" > > > OR > > > $stmt="SELECT fruit FROM tree WHERE fruit in ($fruit1,$fruit2)" > > > > > > The prepare call fails > > > Can't call method "prepare" on an undefined value > > > > This looks as if $dbh is undefined. Check if connect actually succeeded > > before continuing (You may want to use RaiseError). > > > > For creating an IN clause I would use something like: > > > > $stmt="SELECT fruit FROM tree WHERE fruit in (" . > > join(',', map { "?" } @fruits); > > > > $sth = $dbh->prepare($stmt); > > $sth->execute(@fruits); > > You need to use quotes, the correct syntext is > $stmt="SELECT fruit FROM tree WHERE fruit in ('$fruit1','$fruit2')" Not a good idea unless you are absolutely sure that $fruit1, $fruit2 etc. never contain apostrophes. If you need to generate the whole query string at once, use $dbh->quote. But generally, using placeholders is preferrable. hp -- _ | Peter J. Holzer | My definition of a stupid question is |_|_) | Sysadmin WSR / LUGA | "a question that if you're embarassed to | | | [EMAIL PROTECTED] | ask it, you stay stupid." __/ | http://www.hjp.at/ | -- Tim Helck on dbi-users, 2001-07-30
msg09470/pgp00000.pgp
Description: PGP signature