On 01/10/2011 23:16, Jeffrey Joh wrote:
>
> I am trying to run an insert statement with DBI.
>
> $dbh->do(q{insert into zillow_table values
> (?,?,?,?,?,?,?,?)},undef,($homeid,$code,$text,$pid,$street,$city,$state,$zlastupdated));
>
> However, I get "Cannot bind a reference" error. Why does that occur?
> $dbh is part of a foreach loop and several of the executed variables
> are null/undefined.
Your problem is almost certainly because one of your bound variables
$homeid
$code
$text
$pid
$street
$city
$state
$zlastupdated
is set to a reference. You can only bind values that are set to a
string, a number, or undef. You should check the values of your
variables before each insert to find where it is going wrong.
Also, if you are executing the insertion in a loop then you should first
prepare it outside the loop, otherwise the same SQL statement is
wastefully being prepared many times. Something like
my $insert = $dbh->prepare(q{insert into zillow_table values
(?,?,?,?,?,?,?,?)});
foreach (...) {
$insert->execute($homeid,$code,$text,$pid,$street,$city,$state,$zlastupdated);
}
HTH,
Rob
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/