>  기사  >  백엔드 개발  >  PHP가 Oracle 저장 프로시저를 호출하는 이유는 모든 변수가 바인딩되어 있지 않기 때문입니다.

PHP가 Oracle 저장 프로시저를 호출하는 이유는 모든 변수가 바인딩되어 있지 않기 때문입니다.

巴扎黑
巴扎黑원래의
2016-11-08 11:46:511650검색

오늘 저는 PHP를 사용하여 Oracle 저장 프로시저를 호출할 때 항상 이러한 오류가 발생한다는 것을 발견했습니다.

ORA-01008: 모든 변수가 바인딩되지 않았습니다

오랜 고민 끝에 변수 이름이 잘못 쓰여 있는 것을 발견했습니다.

<?php
$conn = oci_connect(&#39;SCOTT&#39;,&#39;TIGER&#39;) or die;// 建立连接 
if (!$conn) { 
$e = oci_error(); 
print htmlentities($e[&#39;message&#39;]); 
exit; 
} 
$sql = &#39;BEGIN pack_gt_calc.Pro_gt_Confirm(:year, :week, :errno, :errmsg); END;&#39;; // 查询语句 
$stid = oci_parse($conn, $sql); // 配置SQL语句,准备执行 
if (!$stid) { 
$e = oci_error($conn); 
print htmlentities($e[&#39;message&#39;]); 
exit; 
}
//  Bind the input parameter
oci_bind_by_name($stid,&#39;:year&#39;,$year,32);
// Bind the input parameter
oci_bind_by_name($stid,&#39;:week&#39;,$week,32);
// Bind the output parameter
oci_bind_by_name($stid,&#39;:errno&#39;,$error,32);
// Bind the output parameter,变量名 ermsg 写错了
oci_bind_by_name($stid,&#39;:ermsg&#39;,$errmsg,64);
// Assign a value to the input 
$year = &#39;2016&#39;;
$week = &#39;4&#39;;
$r = oci_execute($stid); // 执行SQL。OCI_DEFAULT表示不要自动commit 
if(!$r) { 
$e = oci_error($stid); 
echo htmlentities($e[&#39;message&#39;]); 
exit; 
} 
echo "errmsg is : $error<br>";
echo "errmsg is : $errmsg<br>";
oci_close($conn); 
?>


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.