代码中很少有地方对数据库有6-8个查询,查询,各种(select,insert,update,procedure call)不能把所有的查询合二为一,我赶紧写了类似什么的函数代码是必须的,但功能本身并不好看。然而,还需要能够将多个变量附加到请求中。
也许有人,有类似的东西或帮助我纠正这个功能。
更新:问题已解决。
function execSql($conn,$xsql,$sql_no,$return_val,
$binding_val_name,$binding_val,
$bind_additional1,$bind_additional2){
$stmt = oci_parse($conn, $xsql);
if($binding_val_name !='')
if($bind_additional1)
oci_bind_by_name($stmt, $binding_val_name,
$binding_val,$bind_additional1,$bind_additional2);
else
oci_bind_by_name($stmt, $binding_val_name, $binding_val);
oci_execute($stmt, OCI_NO_AUTO_COMMIT);
if($return_val!='')
oci_fetch_all($stmt,$result);
checkError($stmt,$sql_no.'. '.$xsql);
oci_free_statement($stmt);
if($return_val!=''&&$return_val!='1')
return $result[$return_val][0];
if($binding_val_name!='')
return $binding_val;
}
和调用示例
$doc = execSql($conn, $sql,'2', '',':doc','',8, SQLT_INT);
$reg_key = execSql($conn, $select,'3', 'REG_KEY',':doc',$doc);
使用数组
if($binding_val_name !='')
if(is_array($binding_val))
if($bind_additional1[0])
for ($i=0; $i < count($bind_additional1) ; $i++) {
oci_bind_by_name($stmt, $binding_val_name[$i],
$binding_val[$i],$bind_additional1[$i],$bind_additional2[$i]);.
}
else
for ($i=0; $i < count($bind_additional1) ; $i++) {
oci_bind_by_name($stmt, $binding_val_name[$i], $binding_val[$i]);
}
else
if($bind_additional1)
oci_bind_by_name($stmt, $binding_val_name,
$binding_val,$bind_additional1,$bind_additional2);
else
oci_bind_by_name($stmt, $binding_val_name, $binding_val);