> -----Original Message-----
> From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
> Sent: Friday, August 06, 2004 6:09 PM
> To: jason corbett; perl beginners
> Subject: Re: Using binding in order to pass values to a sql statement.
> 
> 
> > 
> > Hello all. I am trying to use bind_param to create a list 
> of values in
> the form of an array. Then I want to query the data base 
> using a basic sql statement where each value in my list 
> (array) will be sent to the DBI in order to return a value. I 
> am getting and error that says can't call method "bind_param" 
> on defined value at line *&&. Here in the subroutine that 
> will attempt to do this.
> >  
> >  
> >  
> > sub kill_porq{
> > my @banlist=qw(
> > 222497190
> <snip list>
> > 222800122
> > );
> >  my $ban='';
> >  foreach $ban (@banlist){
> >  
> >  
> >  $sth->bind_param (1, "$ban");
> 
> Normally you would prepare the statement once, since it 
> doesn't change. If you prepare it each time through the loop 
> you lose the efficiency gain. So move the prepare before the foreach.
> 
> That will also solve the scoping problem you have, are you 
> using 'strict'?  $sth in the above line should not yet be 
> defined. You should have,
> 
> my $sth;
> 
> Inside the loop, this would help you see the issue.
> 
> > 
> >  
> >  $sth=$dbh->prepare("select request_no, ban, request_sts, 
> status_act,
> NPAC_Process_ind, external_req_no
> >   from vstappo.port_request
> >    where ban = ?
> >  ");
> >  
> >  
> >  $sth->execute();
> >
> 
> You can also call execute with your bind params in the call, 
> so that you only need to make one method call, so,
> 
> $sth->execute($ban);
> 
> Should be sufficient without the 'bind_param' call at all.
>   
> Of course you aren't doing anything with $sth here?  And you 
> will need to store your result set as each execute on the 
> $sth will clear the previous one (I believe).
> 
> Alternatively you could build a "better" statement using the 
> $ban list and pass all of it to the database at once to get 
> all of the data in a single execute.
> 
> > return;
> > }
> > 
> > 
> 
> HTH,

You all right Wiggins ...
Prepare once and execute everywhere :-)


José.


**** DISCLAIMER ****

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to