我怎么能把所有的PHP Oracle错误函数在一个函数


How can I put all PHP Oracle error functions in one function?

我试着构建一个包含所有错误的函数下面是我的例子:

<?php
$stid = oci_parse($conn, "select does_not_exist from dual");
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);  // For oci_execute errors pass the statement handle
    print htmlentities($e['message']);
    print "'n<pre>'n";
    print htmlentities($e['sqltext']);
    printf("'n%".($e['offset']+1)."s", "^");
    print  "'n</pre>'n";
}
?>

我将失去我的时间,如果我重复相同的代码与任何SQL查询,所以我想让函数检查错误像这样

function error($r, $stid){
    if(!$r){
        $error = oci_error($stid);
        $code = "Code"." ".$error["code"];
        $sql = "Sql Statment"." ".$error["sqltext"];
        $Position = "Position"." ".$error["offset"];
        $message = "Message"." ".$error["message"];
        $all = array("code"=>$code, "sql"=>$sql, "Position"=>$Position, "message"=>$message);
            return($all);
        }   

}

我想这样做

$stid = oci_parse($conn, "select does_not_exist from dual");
$r = oci_execute($stid);  
$error = error($r, $stid);
echo $error["message"];
echo $error["sql"];
echo $error["code"];
echo $error["Position"];

但是它不工作_请帮忙做

oci_error()应该在连接上运行,从变量名称中不清楚解析是什么。看起来这可能会有问题。http://php.net/oci_error