Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

phpmyadmin fehler rechte unerlaubte mischung, WWWXXXApc, lilo trying to map files from unnamed device 0x0000", Wwwxxxapc, CAM::PDF::Renderer::TextF Fragen, adodb.recordset error '800a0cc1', php save mails as eml, WWWXXXAPC, sqlexpress database file auto-creation error, sqlexpress database file auto-creation error

Links

XODOX
Impressum
Datenschutz

#1: Cannot bind a reference

Posted on 2011-10-02 00:16:46 by Jeffrey Joh

Hello=2C


I am trying to run an insert statement with DBI.

=20

$dbh->do(q{insert into zillow_table values (?=2C?=2C?=2C?=2C?=2C?=2C?=2C?)}=
=2Cundef=2C($homeid=2C$code=2C$text=2C$pid=2C$street=2C$city =2C$state=2C$zl=
astupdated))=3B

=20

However=2C I get "Cannot bind a reference" error. Why does that occur? $d=
bh is part of a foreach loop and several of the executed variables are null=
/undefined.

=20

Thanks=2C

Jeffrey =

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#2: Re: Cannot bind a reference

Posted on 2011-10-02 02:54:38 by Rob Dixon

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,$sta te,$zlastupdated);
}

HTH,

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#3: RE: Cannot bind a reference

Posted on 2011-10-06 19:03:14 by Jeffrey Joh

Thank you for your help Rob.

=20

How can I write a code to go to next iteration of the foreach loop if there=
is a "Cannot bind a reference" error?


Thanks=2C

Jeffrey



----------------------------------------
> Date: Sun=2C 2 Oct 2011 01:54:38 +0100
> From: rob.dixon@gmx.com
> To: beginners@perl.org
> CC: johjeffrey@hotmail.com
> Subject: Re: Cannot bind a reference
>
> On 01/10/2011 23:16=2C Jeffrey Joh wrote:
> >
> > I am trying to run an insert statement with DBI.
> >
> > $dbh->do(q{insert into zillow_table values (?=2C?=2C?=2C?=2C?=2C?=2C?=
=2C?)}=2Cundef=2C($homeid=2C$code=2C$text=2C$pid=2C$street=2 C$city=2C$state=
=2C$zlastupdated))=3B
> >
> > However=2C 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=2C a number=2C or undef. You should check the values of your
> variables before each insert to find where it is going wrong.
>
> Also=2C if you are executing the insertion in a loop then you should firs=
t
> prepare it outside the loop=2C otherwise the same SQL statement is
> wastefully being prepared many times. Something like
>
> my $insert =3D $dbh->prepare(q{insert into zillow_table values (?=2C?=2C?=
=2C?=2C?=2C?=2C?=2C?)})=3B
> foreach (...) {
> $insert->execute($homeid=2C$code=2C$text=2C$pid=2C$street=2C $city=2C$stat=
e=2C$zlastupdated)=3B
> }
>
> HTH=2C
>
> Rob =

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#4: Re: Cannot bind a reference

Posted on 2011-10-06 19:08:44 by Zachary Zebrowski

--bcaec51dd5798a907404aea460ac
Content-Type: text/plain; charset=ISO-8859-1

Try this syntax:

my $dbh = DBI::connect("...",{RaiseError=>1}); # Add raise error to your dbh
class, verbosity is good.

my $sql = qq{insert into foo (col1,col2) values (?,?)}; # Seperate sql from
prepare.
my $sth = $dbh->prepare($sql);

foreach my $x (@ary){
$sth->insert($x,'test');
}

On Thu, Oct 6, 2011 at 1:03 PM, Jeffrey Joh <johjeffrey@hotmail.com> wrote:

>
> Thank you for your help Rob.
>
>
>
> How can I write a code to go to next iteration of the foreach loop if there
> is a "Cannot bind a reference" error?
>
>
> Thanks,
>
> Jeffrey
>
>
>
> ----------------------------------------
> > Date: Sun, 2 Oct 2011 01:54:38 +0100
> > From: rob.dixon@gmx.com
> > To: beginners@perl.org
> > CC: johjeffrey@hotmail.com
> > Subject: Re: Cannot bind a reference
> >
> > 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,$sta te,$zlastupdated);
> > }
> >
> > HTH,
> >
> > Rob
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--bcaec51dd5798a907404aea460ac--

Report this message