如何将所有PHP Oracle错误函数放在一个函数中?

时间:2011-04-16 21:21:00

标签: php oracle

我尝试构建一个函数保存所有错误 这是我的例子:

<?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查询重复相同的代码,我将失去我的时间,所以我想让make函数像这样检查错误

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

}

我想要BT喜欢这个

$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"];

但它不起作用 _ 请帮助做到

1 个答案:

答案 0 :(得分:0)

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