I have an array as the described below :
array is $number
array(84) { [0]=> string(0) "" [1]=> string(10) "12345678" [2]=> string(10) "12345679" [3]=> string(10) "12345610" [4]=> string(10) "12345611" [5]=> string(10) "12345612" [6]=> string(10) "12345613" [7]=> string(10) "12345614"}
Now, I want to make the array bind to my sql query as the desribed below :
$sql = " SELECT id,
FROM cust_data
WHERE whatever IN (:number)";
I've tried using the following method :
$stid = oci_parse($conn, $sql); //Query SQL
$idCollection = oci_new_collection($conn, 'ODCINUMBERLIST', 'SYS');
foreach ($number as $num) {
$idCollection->append($num);
}
oci_bind_by_name($stid, ':number', $idCollection,-1, SQLT_NTY);
oci_execute($stid, OCI_DEFAULT);
oci_fetch_all($stid,$result);
var_dump( $result);
But it just give me the result
array(0) { }
Thank you.
See "Binding Multiple Values in an IN Clause" p p169 of the free book from Oracle https://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html
In summary, for a small number of values, use a fixed SQL string with bind variables. Bind null if there are fewer data values than actual bind variables in the SQL. For bigger lists you can build up a SQL string: but still use bind variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.