connect_scope_try5.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --TEST--
  2. Check oci_pconnect try/catch end-of-scope with old_oci_close_semantics Off
  3. --EXTENSIONS--
  4. oci8
  5. --INI--
  6. oci8.old_oci_close_semantics=0
  7. --FILE--
  8. <?php
  9. require(__DIR__.'/details.inc');
  10. // Initialization
  11. $stmtarray = array(
  12. "drop table scope_try5_tab",
  13. "create table scope_try5_tab (c1 number)"
  14. );
  15. if (!empty($dbase))
  16. $c1 = oci_new_connect($user,$password,$dbase);
  17. else
  18. $c1 = oci_new_connect($user,$password);
  19. oci8_test_sql_execute($c1, $stmtarray);
  20. // Run Test
  21. echo "Test 1\n";
  22. // Make errors throw exceptions
  23. set_error_handler(function($x, $y) { throw new Exception($y, $x); });
  24. try
  25. {
  26. if (!empty($dbase))
  27. $c = oci_pconnect($user,$password,$dbase);
  28. else
  29. $c = oci_pconnect($user,$password);
  30. $s = oci_parse($c, "insert into scope_try5_tab values (1)");
  31. oci_execute($s, OCI_DEFAULT); // no commit
  32. $s = oci_parse($c, "insert into scope_try5_tab values (ABC)"); // syntax error -> throws exception
  33. oci_execute($s, OCI_DEFAULT); // no commit
  34. }
  35. catch (Exception $e)
  36. {
  37. echo "Caught Exception: ". $e->getMessage(), "\n";
  38. var_dump($c);
  39. // Verify data is not yet committed
  40. $s1 = oci_parse($c1, "select * from scope_try5_tab");
  41. oci_execute($s1);
  42. oci_fetch_all($s1, $r);
  43. var_dump($r);
  44. // Now commit
  45. oci_commit($c);
  46. }
  47. // Verify data was committed in the Catch block
  48. $s1 = oci_parse($c1, "select * from scope_try5_tab");
  49. oci_execute($s1);
  50. oci_fetch_all($s1, $r);
  51. var_dump($r);
  52. // Cleanup
  53. $stmtarray = array(
  54. "drop table scope_try5_tab"
  55. );
  56. oci8_test_sql_execute($c1, $stmtarray);
  57. echo "Done\n";
  58. ?>
  59. --EXPECTF--
  60. Test 1
  61. Caught Exception: oci_execute(): ORA-%r(00984|57000: TT2957)%r: %s
  62. resource(%d) of type (oci8 persistent connection)
  63. array(1) {
  64. ["C1"]=>
  65. array(0) {
  66. }
  67. }
  68. array(1) {
  69. ["C1"]=>
  70. array(1) {
  71. [0]=>
  72. string(1) "1"
  73. }
  74. }
  75. Done