On 2002-03-07 08:16:04 -0500, [EMAIL PROTECTED] wrote:
[Haven't seen the original message, so I'm replying to Tim's instead of
Andy's]
> -----Original Message-----
> From: Andy Crichton [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 07, 2002 5:21 AM
> To: [EMAIL PROTECTED]
> Subject: Using IN with prepare clause
> 
> 
> Hi,
>    Sorry if this is covered somewhere , I looked about but was unable to
> find the answer.
> 
> 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);

        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

Attachment: msg09468/pgp00000.pgp
Description: PGP signature

Reply via email to