testoci8cursor.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /*
  3. @version v5.20.17 31-Mar-2020
  4. @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. Released under both BSD license and Lesser GPL library license.
  7. Whenever there is any discrepancy between the two licenses,
  8. the BSD license will take precedence.
  9. Set tabs to 4 for best viewing.
  10. Latest version is available at http://adodb.org/
  11. */
  12. /*
  13. Test for Oracle Variable Cursors, which are treated as ADOdb recordsets.
  14. We have 2 examples. The first shows us using the Parameter statement.
  15. The second shows us using the new ExecuteCursor($sql, $cursorName)
  16. function.
  17. ------------------------------------------------------------------
  18. -- TEST PACKAGE YOU NEED TO INSTALL ON ORACLE - run from sql*plus
  19. ------------------------------------------------------------------
  20. -- TEST PACKAGE
  21. CREATE OR REPLACE PACKAGE adodb AS
  22. TYPE TabType IS REF CURSOR RETURN tab%ROWTYPE;
  23. PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames in varchar);
  24. PROCEDURE data_out(input IN varchar, output OUT varchar);
  25. procedure myproc (p1 in number, p2 out number);
  26. END adodb;
  27. /
  28. CREATE OR REPLACE PACKAGE BODY adodb AS
  29. PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames in varchar) IS
  30. BEGIN
  31. OPEN tabcursor FOR SELECT * FROM tab where tname like tablenames;
  32. END open_tab;
  33. PROCEDURE data_out(input IN varchar, output OUT varchar) IS
  34. BEGIN
  35. output := 'Cinta Hati '||input;
  36. END;
  37. procedure myproc (p1 in number, p2 out number) as
  38. begin
  39. p2 := p1;
  40. end;
  41. END adodb;
  42. /
  43. ------------------------------------------------------------------
  44. -- END PACKAGE
  45. ------------------------------------------------------------------
  46. */
  47. include('../adodb.inc.php');
  48. include('../tohtml.inc.php');
  49. error_reporting(E_ALL);
  50. $db = ADONewConnection('oci8');
  51. $db->PConnect('','scott','natsoft');
  52. $db->debug = 99;
  53. /*
  54. */
  55. define('MYNUM',5);
  56. $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS,'A%'); END;");
  57. if ($rs && !$rs->EOF) {
  58. print "Test 1 RowCount: ".$rs->RecordCount()."<p>";
  59. } else {
  60. print "<b>Error in using Cursor Variables 1</b><p>";
  61. }
  62. print "<h4>Testing Stored Procedures for oci8</h4>";
  63. $stid = $db->PrepareSP('BEGIN adodb.myproc('.MYNUM.', :myov); END;');
  64. $db->OutParameter($stid, $myov, 'myov');
  65. $db->Execute($stid);
  66. if ($myov != MYNUM) print "<p><b>Error with myproc</b></p>";
  67. $stmt = $db->PrepareSP("BEGIN adodb.data_out(:a1, :a2); END;",true);
  68. $a1 = 'Malaysia';
  69. //$a2 = ''; # a2 doesn't even need to be defined!
  70. $db->InParameter($stmt,$a1,'a1');
  71. $db->OutParameter($stmt,$a2,'a2');
  72. $rs = $db->Execute($stmt);
  73. if ($rs) {
  74. if ($a2 !== 'Cinta Hati Malaysia') print "<b>Stored Procedure Error: a2 = $a2</b><p>";
  75. else echo "OK: a2=$a2<p>";
  76. } else {
  77. print "<b>Error in using Stored Procedure IN/Out Variables</b><p>";
  78. }
  79. $tname = 'A%';
  80. $stmt = $db->PrepareSP('select * from tab where tname like :tablename');
  81. $db->Parameter($stmt,$tname,'tablename');
  82. $rs = $db->Execute($stmt);
  83. rs2html($rs);