connect_scope_try6.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --TEST--
  2. Check oci_pconnect try/catch end-of-scope with old_oci_close_semantics On
  3. --EXTENSIONS--
  4. oci8
  5. --INI--
  6. oci8.old_oci_close_semantics=1
  7. --FILE--
  8. <?php
  9. require(__DIR__.'/details.inc');
  10. // Initialization
  11. $stmtarray = array(
  12. "drop table scope_try6_tab",
  13. "create table scope_try6_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_try6_tab values (1)");
  31. oci_execute($s, OCI_DEFAULT); // no commit
  32. $s = oci_parse($c, "insert into scope_try6_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_try6_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_try6_tab");
  49. oci_execute($s1);
  50. oci_fetch_all($s1, $r);
  51. var_dump($r);
  52. // Cleanup
  53. $stmtarray = array(
  54. "drop table scope_try6_tab"
  55. );
  56. oci8_test_sql_execute($c1, $stmtarray);
  57. echo "Done\n";
  58. ?>
  59. --EXPECTF--
  60. Deprecated: Directive oci8.old_oci_close_semantics is deprecated%s
  61. Test 1
  62. Caught Exception: oci_execute(): ORA-%r(00984|57000: TT2957)%r: %s
  63. resource(%d) of type (oci8 persistent connection)
  64. array(1) {
  65. ["C1"]=>
  66. array(0) {
  67. }
  68. }
  69. array(1) {
  70. ["C1"]=>
  71. array(1) {
  72. [0]=>
  73. string(1) "1"
  74. }
  75. }
  76. Done