From: Tim Bunce <[EMAIL PROTECTED]>
> On Mon, Sep 13, 2004 at 06:22:13PM +0100, Martin Moss wrote:
> > All,
> > 
> > Can I do this?
> > 
> > $sth->bind_param_inout($#execute_args+1,\$new_id,38);
> > $sth->execute(@execute_args);
> > 
> > When I try I get the following error
> > Can't rebind or change param :p6 in/out mode after
> > first bind (1 => 0) at ...........
> > 
> > I wish to pass several arguments, into the sth, I wish
> > to use placeholders so I can cache this $sth, 
> 
> Use bind_param() or bind_param_inout() for all the params
> and then call execute() with no arguments.
> 
> Tim.

I wonder ... how about adding a method bind_params() like this:

sub bind_params {
        my $sth = shift;
        my $pos = (ref($_[0]) ? 1 : shift);
        for my $param (@{$_[0]}) {
                $sth->bind_param($pos++, $param);
        }
}

So that this could be shortened to

        $sth->bind_params([EMAIL PROTECTED]); # default position is 1
        $sth->bind_param_inout($#execute_args+1,\$new_id,38);

I know I can have the loop in the script, but this looks kinda more 
readable to me.

Sorry if this was already rejected ;-)

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

Reply via email to