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