[英]How to bind an array contains string to oracle query (IN clause) using any method(oci/pdo) in PHP?
I have an array as the described below : 我有一个数组,如下所述:
array is $number 数组是$ 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查询,如下所示:
$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) { } 数组(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 请参见Oracle免费书中的“在IN子句中绑定多个值” p169页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. 总之,对于少量的值,请使用带有绑定变量的固定SQL字符串。 Bind null if there are fewer data values than actual bind variables in the SQL. 如果数据值少于SQL中的实际绑定变量,则绑定null。 For bigger lists you can build up a SQL string: but still use bind variables. 对于更大的列表,您可以构建一个SQL字符串:但仍使用绑定变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.