Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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 f
orm of an array. Then I want to query the data base using a basic sql statem
ent where each value in my list (array) will be sent to the DBI in order to 
return a value. I am gettin
g and error that says can't call method "bind_param" on defined value at lin
e *&&. Here in the subroutine that will attempt to do this.



sub kill_porq{
my @banlist=qw(
222497190
291529832
285471249
280768305
276573798
278628710
297888281
297002394
271831939
127465
245710698
314086723
347803890
253926979
226200204
250702348
246597179
301791980
332270292
344909948
283580543
325838931
349835609
248436566
240499101
245185000
353432496
246334241
279430907
222800122
);
my $ban='';
foreach $ban (@banlist){


$sth->bind_param (1, "$ban");


$sth=$dbh->prepare("select request_no, ban, request_sts, status_act, NPAC_Pr
ocess_ind, external_req_no
from vstappo.port_request
where ban = ?
");


$sth->execute();

return;
}


Report this thread to moderator Post Follow-up to this message
Old Post
Jason Corbett
08-07-04 08:55 AM


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,

http://danconia.org

Report this thread to moderator Post Follow-up to this message
Old Post
Wiggins D Anconia
08-07-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:40 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.