使用oracle 10g和php在单个数据库连接中执行多个查询
我想使用Oracle10g和php在单个数据库连接中运行多个sql查询。这里对于每个sql查询,我都必须创建数据库连接。是否有任何方法可以在单个数据库连接中运行多个sql查询,或者我们只能以这种方式获取数据?因为当我们必须运行50个查询时,我们必须像下面这样写50次使用oracle 10g和php在单个数据库连接中执行多个查询,php,sql,oracle,Php,Sql,Oracle,我想使用Oracle10g和php在单个数据库连接中运行多个sql查询。这里对于每个sql查询,我都必须创建数据库连接。是否有任何方法可以在单个数据库连接中运行多个sql查询,或者我们只能以这种方式获取数据?因为当我们必须运行50个查询时,我们必须像下面这样写50次 <?php include("mydb.php"); // run query $sql6 = "select * from dat where to_char(WD,'dd/mm')='19/08'"; $stid6=oc
<?php
include("mydb.php");
// run query
$sql6 = "select * from dat where to_char(WD,'dd/mm')='19/08'";
$stid6=oci_parse($conn, $sql6);
// set array
$arr6 = array();
if(!$stid6){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}
$r6=oci_execute($stid6);
if(!$r6){
$e=oci_error($stid6);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}
// look through query
while($row = oci_fetch_array($stid6,OCI_ASSOC)){
// add each row returned into an array
$arr6[] = array(($row['WD']) , (float)$row['DATA']);
}
oci_free_statement($stid6);
oci_close($conn);
?>
<?php
include("mydb.php");
// run query
$sql7 = "select * from dat where to_char(WD,'dd/mm')='11/03'";
$stid7 = oci_parse($conn, $sql7);
// set array
$arr7 = array();
if(!$stid7){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}
$r7=oci_execute($stid7);
if(!$r7){
$e=oci_error($stid7);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}
// look through query
while($row = oci_fetch_array($stid7,OCI_ASSOC)){
// add each row returned into an array
$arr7[] = array(($row['WD'])) , (float)$row['DATA']);
}
oci_free_statement($stid7);
oci_close($conn);
?>
................
................
(这应该是一条注释,但有点长)
我不想在这里贬低你,但是你的问题太幼稚了,太幼稚了,以至于应该把它作为离题来讨论
您的代码显示出对变量和变量缺乏理解。从零开始编程课程的第2天应涵盖这些内容。但奇怪的是,它包含了一些更复杂的特定于PHP的编程,但是使用了SQL——看起来好像是其他人编写的代码是一种快速的黑客攻击,现在您正在尝试扩展它的功能
您使用的是Oracle数据库,这引发了各种各样的问题,问您为什么要尝试这样做(Oracle很昂贵;有人怎么能负担得起,但却负担不起为您提供所需技能?)
正如您所描述的,问题的解决方案是将脚本重新实现为一个函数,将OCI连接和SQL语句作为参数,然后简单地
<?php
include("mydb.php");
$queries=array(
"select * from dat where to_char(WD,'dd/mm')='11/03'",
"select * from dat where to_char(WD,'dd/mm')='19/08'"
);
foreach ($queries as $sql) {
run_qry($sql, $conn);
}
oci_close($conn);
exit;
function run_query($sql, $conn)
{
$stid=oci_parse($conn, $sql);
// set array
$arr = array();
if(!$stid){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}
...
oci_free_statement($stid);
return $arr;
}