xref: /PHP-8.2/ext/oci8/tests/conn_attr_2.phpt (revision 93e509fd)
1--TEST--
2Set and get of connection attributes across persistent connections and sysdba connection.
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
8$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
9require(__DIR__.'/skipif.inc');
10
11if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
12if ($test_drcp) die("skip output might vary with DRCP");
13
14preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
15if (!(isset($matches[0]) && $matches[1] >= 10)) {
16    die("skip expected output only valid when using Oracle 10g or greater database server");
17}
18?>
19--INI--
20oci8.privileged_connect = On
21--FILE--
22<?php
23
24$testuser     = 'testuser_attr_2';  // Used in conn_attr.inc
25$testpassword = 'testuser';
26
27require(__DIR__."/conn_attr.inc");
28
29$attr_array = array('MODULE','ACTION','CLIENT_INFO','CLIENT_IDENTIFIER');
30
31echo"**Set values using pconnect-1**\n";
32
33var_dump($pc1 = oci_pconnect($testuser,$testpassword,$dbase));
34foreach($attr_array as $attr) {
35    set_attr($pc1,$attr,100);
36}
37
38//  using pc1 again
39echo"\n**Get values using pconnect-2**\n";
40var_dump($pc3 = oci_pconnect($testuser,$testpassword,$dbase));
41foreach($attr_array as $attr) {
42    get_attr($pc3,$attr);
43}
44
45// Get with different pconnect
46echo"\n**Get values using pconnect-3**\n";
47var_dump($pc2 = oci_pconnect($testuser,$testpassword,$dbase,'UTF8'));
48foreach($attr_array as $attr) {
49    get_attr($pc2,$attr);
50}
51
52oci_close($pc1);
53oci_close($pc2);
54oci_close($pc3);
55
56// Re-open a persistent connection and check for the attr values.
57echo "\n**Re-open a pconnect()**\n";
58var_dump($pc4 = oci_pconnect($testuser,$testpassword,$dbase));
59foreach($attr_array as $attr) {
60    get_attr($pc4,$attr);
61}
62oci_close($pc4);
63
64// Test with SYSDBA connection.
65echo "\n**Test with SYSDBA connection**\n";
66$sys_c1 = @oci_pconnect($testuser,$testpassword,$dbase,false,OCI_SYSDBA);
67var_dump($sys_c1);
68if (!$sys_c1) {
69    $e = oci_error();
70    if ($e['code'] != 1031 && $e['code'] != 1017) {
71        var_dump($e);
72    }
73} else {
74    set_attr($sys_c1,'ACTION',10);
75    get_sys_attr($sys_c1,'ACTION');
76    get_attr($sys_c1,'ACTION');
77    oci_close($sys_c1);
78}
79
80clean_up($c);
81
82echo "Done\n";
83?>
84--EXPECTF--
85**Set values using pconnect-1**
86resource(%d) of type (oci8 persistent connection)
87Value of MODULE has been set successfully
88Value of ACTION has been set successfully
89Value of CLIENT_INFO has been set successfully
90Value of CLIENT_IDENTIFIER has been set successfully
91
92**Get values using pconnect-2**
93resource(%d) of type (oci8 persistent connection)
94The value of MODULE is PHP TEST100
95The value of ACTION is TASK100
96The value of CLIENT_INFO is INFO1100
97The value of CLIENT_IDENTIFIER is ID00100
98
99**Get values using pconnect-3**
100resource(%d) of type (oci8 persistent connection)
101The value of MODULE is %s
102The value of ACTION is
103The value of CLIENT_INFO is
104The value of CLIENT_IDENTIFIER is
105
106**Re-open a pconnect()**
107resource(%d) of type (oci8 persistent connection)
108The value of MODULE is PHP TEST100
109The value of ACTION is TASK100
110The value of CLIENT_INFO is INFO1100
111The value of CLIENT_IDENTIFIER is ID00100
112
113**Test with SYSDBA connection**
114bool(false)
115Done
116