Page 1 of 1

Using oci_fetch_all() w/ SQL that contains an "IN" clause...

Posted: Thu Apr 21, 2016 9:20 am
by Wolf_22
I'm trying to retrieve multiple records from an Oracle database using the following SQL:
SELECT my_id
FROM my_table
WHERE my_id IN ('id1', 'id2', 'id3');
To do this, I've tried to use the following PHP:

Code: Select all

$search_string = array('id1', 'id2', 'id3');

$placeholders = array();
$bind = array();

$conn = oci_connect('admin', '1234', 'testdb.mydomain.com/TEST');

foreach($search_string as $index => $filter) {
	$placeholders[] = ':filter'.$index;
	$bind[':filter'.$index] = $filter;
}


$stid = '
    SELECT		my_id
    FROM		my_table
    WHERE		my_id IN ('.implode(',',$placeholders).')
';


$stid = oci_parse($conn,$stid);

foreach($bind as $k=>$v){
    oci_bind_by_name($stid, $k, $v);
}

$r = oci_execute($stid);

oci_fetch_all($stid, $res, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);

print '<pre>';
var_dump($res);
print '</pre>';

oci_free_statement($stid);
oci_close($conn)
Unfortunately, it seems to only retrieve 1 record when there's 3 in the database (which I verified w/ SQL Developer).

Why is it retrieving only 1 record? I would expect to see 3 in $res...

Any insights into this would be appreciated.

Re: Using oci_fetch_all() w/ SQL that contains an "IN" claus

Posted: Mon Apr 25, 2016 12:58 pm
by Wolf_22
Okay, so I'm going to use PDO instead of OCI. With PDO, I'm able to do everything I need without any headaches. I guess OCI is pretty buggy...?