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