JupiterHost.Net [mailto:[EMAIL PROTECTED] wrote:

> perldoc DBI
> has this:
>     $rv  = $dbh->do($statement, \%attr, @bind_values);
> 
> So would this be a proper use of it:
> 
>   $dbh->do(
>     'INSERT INTO Stuff (Id,Foo) VALUES (NULL,?)',
>      undef,
>      qw('foo' 'bar' 'baz')
>   ) or die ....
> # IE undef foro \%attr and include quoted data
> 
> That would essencially run:
>   INSERT INTO Stuff (Id,Foo) VALUES (NULL,'foo');
>   INSERT INTO Stuff (Id,Foo) VALUES (NULL,'bar');
>   INSERT INTO Stuff (Id,Foo) VALUES (NULL,'baz');
> since do() does the prepare and execute for you.
> correct?

No, that's not right.  Using that syntax, you bind a single value to
each placeholder.  @bind_values is an array because a statement can
contain multiple placeholders.

If you want to bind an array of values to a single placeholder, one
value per execution, you have to use bind_param_array() and
execute_array().  Alternatively, you can just loop over the values
explicitly.

(Also, you shouldn't have single quotes inside the qw().)

Ronald


Reply via email to