On Wed, 02 Apr 2003 23:03:30 +0200, you (K�re Olai Lindbach
<[EMAIL PROTECTED]>) wrote:

>On Wed, 2 Apr 2003 13:51:01 -0700, you (Gregg Allen <[EMAIL PROTECTED]>)
>wrote:
>
>>
>>Can someone tell me why this statement works interactively but not from 
>>a perl script?
>>
>>
>>MySQL>   SELECT * FROM MESSAGES WHERE pkey = $pkey\G ;
>>
>>This prints the output in a very nice, readable format.
>>
>>but:
>>
>>my $query = " SELECT * FROM MESSAGES WHERE pkey = $pkey\\G ";
>>
>>$sth->prepare($query);
>>
>>$sth->execute();
>
>The execute command does what \G does in an interative SQL-client
>shell, so only use your plain SQL-syntaks.
>
>I would also suggest use of binding:
>
>my $query = " SELECT * FROM MESSAGES WHERE pkey = ?";
>$sth->prepare($query);
>$sth->execute($pkey);
>
>If this is done by using DBI-module, please read about binding in that
>documentation.

Ops, I used a bit too much pasting from OP:

my $dbh = DBI->connect(......);

my $query = " SELECT * FROM MESSAGES WHERE pkey = ?";
# Donot use either \G or ; as end of the SQL-syntaxs itself.

my $sth = $dbh->prepare($query);

my $rv = $sth->execute($pkey);


-- 
mvh/Regards
K�re Olai Lindbach

Reply via email to