SPUG: Turning off auto-quoting during DBI Binding.
Ronald J Kimball
rjk-spug at tamias.net
Tue Apr 8 07:24:46 PDT 2008
On Mon, Apr 07, 2008 at 08:30:35PM -0700, Stephen Blum wrote:
> Hey SPUG Team,
>
> How does one turn off the annoying and sometimes unneeded auto-quoting
> that occurs during DBI Bindings? I have searched the net for a while now
> and have found little on the subject.
> example:
>
> $sql = q(thrrr_id in (?));
> $sth = $dbh->prepare($sql);
> $sth->execute( q(1,2,3,4,5) );
>
> DBI executes this: thrrr_id in ('1,2,3,4,5')
> But I want to execute this: thrrr_id in (1,2,3,4,5)
>
> DBI adds quotes and I don't want them. If there is no way around this I
> can forgo the performance/convenience of bindings.
Here's one approach to binding a list of values to placeholders:
$sql = "thrrr_id in (@{[ join ',', ('?') x @list ]})";
$sth = $dbh->prepare($sql);
$sth->execute(@list);
Ronald
More information about the spug-list
mailing list