脚本宝典收集整理的这篇文章主要介绍了用于’IN’语句的PHP OCI8绑定(未知数量)参数,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
例如,给出以下查询
select * From table1 where id > :id_1 and id in (:id_array_of_unkNown_size)
和要绑定的变量数组
$bind_array = array( ':id_1' => '1',': id_array_of_unkNown_size' => array('7','2','5',),);
另外需要注意的是,在我的特定情况下,输入数组($bind_array)可能包含也可能不包含bind元素的子数组.它也可以是以下
select * from table1 where id > :id_1 and id != :id_2
和
$bind_array = array( ':id_1' => '1',':id_2' => '5',);
<?PHP $ids = array( 103,104 ); $conn = oci_pconnect($user,$pass,$tns); // Using oracle table() function to get the ids from the subquery $sql = 'SELECT * FROM employees WHERE employee_id IN (SELECT column_value FROM table(:ids))'; $stmt = oci_parse($conn,$sql); // Create collection of numbers. Build in tyPE for strings is ODCIVArchAR2LIST,but you can also create own types. $IDCollection = oci_new_collection($conn,'ODCINUMBERLIST','Sys'); // Maximum length of collections of type ODCINUMBERLIST is 32767,maybe you should check that! foreach ($ids as $id) { $idCollection->append($id); } oci_bind_by_name($stmt,':ids',$idCollection,-1,sqlT_NTY); oci_execute($stmt,OCI_DEFAULT); oci_fetch_all($stmt,$return); oci_free_statement($stmt); oci_close($conn); ?>
以上是脚本宝典为你收集整理的用于’IN’语句的PHP OCI8绑定(未知数量)参数全部内容,希望文章能够帮你解决用于’IN’语句的PHP OCI8绑定(未知数量)参数所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。