Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ';在';陈述_Php_Sql_Oracle Call Interface - Fatal编程技术网

Php ';在';陈述

Php ';在';陈述,php,sql,oracle-call-interface,Php,Sql,Oracle Call Interface,对于SQL IN子句,在将SQL与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',), );

对于SQL IN子句,在将SQL与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\u array)
可能包含也可能不包含bind元素的子数组。它也可以是下面的

select * from table1
where id > :id_1
and id !=  :id_2


您应该使用另一个函数绑定数组-oci\u bind\u array\u by\u name

您不能仅仅用数组对象替换:variable by oci\u bind\u by\u name
一种方法是在in子句中绑定少量固定数量的值,如的文档中所述。还有一种解决方案,可以将多个条件与数量可变的值绑定在一起

<?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);

?>

您可以在oci中绑定到吗?我认为在PDO中你不能绑定到
<?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);

?>