On 2003-09-23 20:30:10 -0700, Dave Anderson wrote:
> I am having a heck of a time doing a "SELECT FROM TAB WHERE COL1='val'
> and COL2 IN ('1','2')" where the '1','2' is coming from an array that is
> returned from a multi-select box built with CGI $q->scrolling_list with
> "multiple" set to "true". I see that bind_param_array can take an array
> as a bind value, but I want to have several arrays of varying sizes in
> my query. bind_param_array will not do this, nor will it work for a SELECT.
>
bind_param_array is for use with execute_array. It will execute the same
query for each value in the array.
> $sthHistory = $dbh->prepare_cached('SELECT STATUS,COMMENTS,LABEL
> FROM STATUSCURRENTTAB WHERE ID in ?');
You cannot expand a single "?" to a list of values. You have to
construct a query string with the appropriate number of placeholders
first, then you can simply call execute:
$query = 'SELECT STATUS,COMMENTS,LABEL
FROM STATUSCURRENTTAB WHERE ID in (' .
join(',', map { '?' } @array) . ')';
$sthHistory = $dbh->prepare_cached($query);
$sthHistory->execute(@array);
hp
--
_ | Peter J. Holzer | Unser Universum w�re betr�blich
|_|_) | Sysadmin WSR / LUGA | unbedeutend, h�tte es nicht jeder
| | | [EMAIL PROTECTED] | Generation neue Probleme bereit.
__/ | http://www.hjp.at/ | -- Seneca, naturales quaestiones
pgp00000.pgp
Description: PGP signature
