List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:February 17 2000 12:42pm
Subject:Re: DBI placeholders
View as plain text  
At 2:05 AM -0500 2000-02-17, Laura wrote:
>I would appreciate any help on the following DBI commands. I am 
>using placeholders for the first time and cannot seem to get it 
>right. Prepare goes through fine but, I get "Can't add $name" on the 
>execute command.
>Using MySQL 3.21.33

Probable cause:  The syntax for INSERT is "INSERT INTO tbl_name ...".
The INTO keyword is optional only as of MySQL 3.22.5.

Change your statement from "INSERT task ..." to "INSERT INTO task ..."

>     $dbh = DBI->connect (@db_connect) or &cgierr ("Connection Error. 
>Reason: " . $DBI::errstr);
>     $sth = $dbh->prepare (qq{INSERT task (colname1,colname2,colname3,colname4)
>             VALUES (?,?,?,?)}) || print "Can't prepare";
>     foreach $name(@name) {
>    $sth->execute ("$name","$value2","$value3","$value4") || print 
>"Can't add $name";

By the way, the double quotes around "$name", "$value2", "$value3", and
"$value4" are superfluous here.  That won't make your query fail, but
they're not necessary around simple variable references.

>     }
>     $sth->finish();
>             $dbh->disconnect or &cgierr ("Can't Disconnect. Reason: 
>Thank you for any suggestions

Paul DuBois, paul@stripped
DBI placeholdersLaura17 Feb
  • Re: DBI placeholdersThimble Smith17 Feb
  • Re: DBI placeholdersPaul DuBois17 Feb