xref: /PHP-8.1/ext/oci8/tests/drcp_connect1.phpt (revision b5a14e6c)
1--TEST--
2DRCP: oci_connect()
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs (Calling PL/SQL from SQL is not supported in TimesTen)
8require(__DIR__.'/skipif.inc');
9?>
10--INI--
11oci8.connection_class=test
12oci8.old_oci_close_semantics=0
13--FILE--
14<?php
15
16require __DIR__."/details.inc";
17require __DIR__."/drcp_functions.inc";
18
19// Open a number of connections with oci_connect and oci_pconnect and verify
20// whether we get a used session with DRCP.
21// To verify this, we change the value of a PL/SQL package variable in one
22// session and query for this through another connection
23
24echo "Test 1a\n";
25var_dump($conn1 = oci_connect($user,$password,$dbase));
26// Create the package
27drcp_create_package($conn1);
28
29echo "Test 1b\n";
30// OCI_CONNECT
31echo " This is with OCI_CONNECT.....\n";
32drcp_select_packagevar($conn1); // Returns 0
33drcp_set_packagevar($conn1,1000);
34oci_close($conn1);
35echo " Connection conn1  closed....\n";
36
37echo "Test 2\n";
38// Second connection should return 0 for the package variable.
39var_dump($conn2 = oci_connect($user,$password,$dbase));
40echo " Select with connection 2\n";
41drcp_select_packagevar($conn2); // Returns 0
42drcp_set_packagevar($conn2,100);
43
44echo "Test 3\n";
45// Third connection. There is no oci_close() for conn2 hence this should
46// return the value set by conn2.
47var_dump($conn3 = oci_connect($user,$password,$dbase));
48echo " Select with connection 3\n";
49drcp_select_packagevar($conn3); // Returns 100
50
51// Close all the connections
52oci_close($conn2);
53oci_close($conn3);
54
55echo "Test 4\n";
56// OCI_PCONNECT
57echo " This is with oci_pconnect().....\n";
58var_dump($pconn1 = oci_pconnect($user,$password,$dbase));
59drcp_set_packagevar($pconn1,1000);
60oci_close($pconn1);
61echo " Connection pconn1  closed....\n";
62
63// Second connection with oci_pconnect should return the same session hence the
64// value returned is what is set by pconn1
65
66echo "Test 5\n";
67var_dump($pconn2 = oci_pconnect($user,$password,$dbase));
68echo " Select with persistent connection 2\n";
69drcp_select_packagevar($pconn2); // Returns 1000
70oci_close($pconn2);
71
72echo "Done\n";
73
74?>
75--EXPECTF--
76Test 1a
77resource(%d) of type (oci8 connection)
78Test 1b
79 This is with OCI_CONNECT.....
80 The value of the package variable is 0
81 Package variable value set to 1000
82 Connection conn1  closed....
83Test 2
84resource(%d) of type (oci8 connection)
85 Select with connection 2
86 The value of the package variable is 0
87 Package variable value set to 100
88Test 3
89resource(%d) of type (oci8 connection)
90 Select with connection 3
91 The value of the package variable is 100
92Test 4
93 This is with oci_pconnect().....
94resource(%d) of type (oci8 persistent connection)
95 Package variable value set to 1000
96 Connection pconn1  closed....
97Test 5
98resource(%d) of type (oci8 persistent connection)
99 Select with persistent connection 2
100 The value of the package variable is 1000
101Done
102