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