xref: /PHP-8.2/ext/oci8/tests/lob_038.phpt (revision b5a14e6c)
1--TEST--
2Array fetch CLOB and BLOB
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9?>
10--FILE--
11<?php
12
13require __DIR__.'/connect.inc';
14require __DIR__.'/create_table.inc';
15
16echo "Test 1: CLOB\n";
17
18$ora_sql = "INSERT INTO
19                       ".$schema.$table_name." (clob)
20                      VALUES (empty_clob())
21                      RETURNING
22                               clob
23                      INTO :v_clob ";
24
25$s = oci_parse($c,$ora_sql);
26$clob = oci_new_descriptor($c,OCI_DTYPE_LOB);
27
28
29oci_bind_by_name($s,":v_clob", $clob,-1,OCI_B_CLOB);
30
31oci_execute($s, OCI_DEFAULT);
32var_dump($clob->save("clob test 1"));
33
34oci_execute($s, OCI_DEFAULT);
35var_dump($clob->save("clob test 2"));
36
37oci_execute($s, OCI_DEFAULT);
38var_dump($clob->save("clob test 3"));
39
40
41$s = oci_parse($c,"select clob from ".$schema.$table_name);
42var_dump(oci_execute($s));
43
44oci_fetch_all($s, $res);
45
46var_dump($res);
47
48
49echo "Test 1b\n";
50
51$s = oci_parse($c, "select clob from ".$schema.$table_name);
52var_dump(oci_execute($s, OCI_DEFAULT));
53while ($row = oci_fetch_array($s, OCI_ASSOC)) {
54    var_dump($row);
55    $result = $row['CLOB']->load();
56    var_dump($result);
57}
58
59
60require __DIR__.'/drop_table.inc';
61
62echo "Test 2: BLOB\n";
63
64require __DIR__.'/create_table.inc';
65
66$ora_sql = "INSERT INTO
67                       ".$schema.$table_name." (blob)
68                      VALUES (empty_blob())
69                      RETURNING
70                               blob
71                      INTO :v_blob ";
72
73$s = oci_parse($c,$ora_sql);
74$blob = oci_new_descriptor($c,OCI_DTYPE_LOB);
75
76
77oci_bind_by_name($s,":v_blob", $blob,-1,OCI_B_BLOB);
78
79oci_execute($s, OCI_DEFAULT);
80var_dump($blob->save("blob test 1"));
81
82oci_execute($s, OCI_DEFAULT);
83var_dump($blob->save("blob test 2"));
84
85oci_execute($s, OCI_DEFAULT);
86var_dump($blob->save("blob test 3"));
87
88$s = oci_parse($c, "select blob from ".$schema.$table_name);
89var_dump(oci_execute($s));
90oci_fetch_all($s, $res);
91var_dump($res);
92
93echo "Test 2b\n";
94
95$s = oci_parse($c, "select blob from ".$schema.$table_name);
96var_dump(oci_execute($s, OCI_DEFAULT));
97while ($row = oci_fetch_array($s, OCI_ASSOC)) {
98    var_dump($row);
99    $result = $row['BLOB']->load();
100    var_dump($result);
101}
102
103
104require __DIR__.'/drop_table.inc';
105
106echo "Done\n";
107
108?>
109--EXPECTF--
110Test 1: CLOB
111bool(true)
112bool(true)
113bool(true)
114bool(true)
115array(1) {
116  ["CLOB"]=>
117  array(3) {
118    [0]=>
119    string(11) "clob test 1"
120    [1]=>
121    string(11) "clob test 2"
122    [2]=>
123    string(11) "clob test 3"
124  }
125}
126Test 1b
127bool(true)
128array(1) {
129  ["CLOB"]=>
130  object(OCILob)#2 (1) {
131    ["descriptor"]=>
132    resource(%d) of type (oci8 descriptor)
133  }
134}
135string(11) "clob test 1"
136array(1) {
137  ["CLOB"]=>
138  object(OCILob)#3 (1) {
139    ["descriptor"]=>
140    resource(%d) of type (oci8 descriptor)
141  }
142}
143string(11) "clob test 2"
144array(1) {
145  ["CLOB"]=>
146  object(OCILob)#2 (1) {
147    ["descriptor"]=>
148    resource(%d) of type (oci8 descriptor)
149  }
150}
151string(11) "clob test 3"
152Test 2: BLOB
153bool(true)
154bool(true)
155bool(true)
156bool(true)
157array(1) {
158  ["BLOB"]=>
159  array(3) {
160    [0]=>
161    string(11) "blob test 1"
162    [1]=>
163    string(11) "blob test 2"
164    [2]=>
165    string(11) "blob test 3"
166  }
167}
168Test 2b
169bool(true)
170array(1) {
171  ["BLOB"]=>
172  object(OCILob)#3 (1) {
173    ["descriptor"]=>
174    resource(%d) of type (oci8 descriptor)
175  }
176}
177string(11) "blob test 1"
178array(1) {
179  ["BLOB"]=>
180  object(OCILob)#4 (1) {
181    ["descriptor"]=>
182    resource(%d) of type (oci8 descriptor)
183  }
184}
185string(11) "blob test 2"
186array(1) {
187  ["BLOB"]=>
188  object(OCILob)#3 (1) {
189    ["descriptor"]=>
190    resource(%d) of type (oci8 descriptor)
191  }
192}
193string(11) "blob test 3"
194Done
195