I have to create an SQL statement of the form

select  * from table where attr1 in ( 1,2,3.....n) and attr2 in ( 'ABC',
'DEF', ....., 'asdf');

where the number of entries within the variable lists is driven by the user
interface.  As a result the number of elements within the lists can go from
one to many.  I would like to use bind variables to represent the variables
lists.  I tried one method where ..

$sql="select * from table where attr1 in ( ? ) and attr2  in ( ? );
$sth->prepare($sql);

$sth->bind_param(1, $string1, {TYPE=>SQL_VARCHAR2});
$sth->bind_param(2, $string2, {TYPE=>SQL_VARCHAR2});

No errors in binding and executing but no records were returned when there
should have been some.


A second technique was to build the SQL statement on the fly based on the
values of attr1 and attr2 select by the user.  The result was SQL statements
of the form
$sql="select * from table where attr1 in (?, ?, ?, ....)  and attr2 in (?,
?, ?, ?...)";
I then bound in each value.

This technique worked but seemed quite laborious.

Is there a quick way is elegant  of doing this kind of thing?  Note that in
this instance attr1 is numeric and attr2 is character strings;

hanks for any help.

Neil McLennan
Environment Canada
Vancouver BC

 <<McLennan,Neil [PYR].vcf>> 

McLennan,Neil [PYR].vcf

Reply via email to