[英]PHP: Multiple SQL Statements
I have a SQL query which looks like this: 我有一个SQL查询,看起来像这样:
$sql = "SELECT * FROM TABLE ...
INSERT ...
DELETE ...";
and I want to use multiple statements when querying the Oracle database. 而且我想在查询Oracle数据库时使用多个语句。 I know in mySQL there is mysqli_multi_query().
我知道在MySQL中有mysqli_multi_query()。 Is this possible in Oracle?
在Oracle中这可能吗?
Thank you. 谢谢。
Taken from: Using PHP and Oracle Database 12c Implicit Result Sets 摘自: 使用PHP和Oracle Database 12c隐式结果集
The new Oracle Database 12c "Implicit Result Sets" (IRS) feature allows query results to be returned from a stored PL/SQL procedure (or a PL/SQL anonymous block) without requiring special PHP code. 新的Oracle Database 12c“隐式结果集”(IRS)功能允许从存储的PL / SQL过程(或PL / SQL匿名块)返回查询结果,而无需特殊的PHP代码。 Support for IRS is available in PHP's OCI8 2.0.0-devel extension when it is compiled and used with Oracle Database 12c.
编译并与Oracle Database 12c一起使用时,PHP的OCI8 2.0.0-devel扩展中提供了对IRS的支持。 (OCI8 2.0 can be compiled and used with other versions of Oracle Database but the available feature set is reduced).
(OCI8 2.0可以编译并与其他版本的Oracle数据库一起使用,但是可用的功能集有所减少)。
<?php
$c = oci_connect('hr', 'welcome', 'localhost/pdborcl');
$sql =
"declare
c1 sys_refcursor;
begin
open c1 for select city from locations where rownum < 4;
dbms_sql.return_result(c1);
open c1 for select first_name, last_name from employees where rownum < 4;
dbms_sql.return_result(c1);
end;";
$s = oci_parse($c, $sql);
oci_execute($s);
while (($s2 = oci_get_implicit_resultset($s))) {
// Now treat $s2 as a distinct query statement resource
$ncols = oci_num_fields($s2);
for ($i = 1; $i <= $ncols; ++$i) {
$colname = oci_field_name($s2, $i);
echo $colname . " ";
}
echo "\n";
while (($row = oci_fetch_row($s2)) != false) {
foreach ($row as $item) {
echo $item . " ";
}
echo "\n";
}
}
?>
Alternatively you can create a stored procedure in Oracle (which can contain multiple statements and output parameters) and then call it from PHP. 或者,您可以在Oracle中创建一个存储过程(该存储过程可以包含多个语句和输出参数),然后从PHP调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.