当前位置:Gxlcms > PHP教程 > PHP调用Oracle存储过程出现notallvariablesbound原因

PHP调用Oracle存储过程出现notallvariablesbound原因

时间:2021-07-01 10:21:17 帮助过:3人阅读

今天发现使用 PHP 调用 Oracle 存储过程总是出现这样的一个错误。

ORA-01008: not all variables bound

后来折腾了很久,发现是变量名写错了。

  1. <!--?php
  2. $conn = oci_connect('SCOTT','TIGER') or die;// 建立连接
  3. if (!$conn) {
  4. $e = oci_error();
  5. print htmlentities($e['message']);
  6. exit;
  7. }
  8. $sql = 'BEGIN pack_gt_calc.Pro_gt_Confirm(:year, :week, :errno, :errmsg); END;'; // 查询语句
  9. $stid = oci_parse($conn, $sql); // 配置SQL语句,准备执行
  10. if (!$stid) {
  11. $e = oci_error($conn);
  12. print htmlentities($e['message']);
  13. exit;
  14. }
  15. // Bind the input parameter
  16. oci_bind_by_name($stid,':year',$year,32);
  17. // Bind the input parameter
  18. oci_bind_by_name($stid,':week',$week,32);
  19. // Bind the output parameter
  20. oci_bind_by_name($stid,':errno',$error,32);
  21. // Bind the output parameter,变量名 ermsg 写错了
  22. oci_bind_by_name($stid,':ermsg',$errmsg,64);
  23. // Assign a value to the input
  24. $year = '2016';
  25. $week = '4';
  26. $r = oci_execute($stid); // 执行SQL。OCI_DEFAULT表示不要自动commit
  27. if(!$r) {
  28. $e = oci_error($stid);
  29. echo htmlentities($e['message']);
  30. exit;
  31. }
  32. echo "errmsg is : $error<br-->";
  33. echo "errmsg is : $errmsg<br>";
  34. oci_close($conn);
  35. ?>

人气教程排行