xref: /PHP-8.1/ext/oci8/tests/fetch_object_2.phpt (revision b5a14e6c)
1--TEST--
2oci_fetch_object() with CLOB and NULL
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');
14
15// Initialization
16
17$stmtarray = array(
18    "drop table fetch_object_2_tab",
19    "create table fetch_object_2_tab (col1 number, col2 CLOB, col3 varchar2(15))",
20    "insert into fetch_object_2_tab values (123, '1st row col2 string', '1 more text')",
21    "insert into fetch_object_2_tab values (456, '2nd row col2 string', NULL)",
22    "insert into fetch_object_2_tab values (789, '3rd row col2 string', '3 more text')",
23);
24
25oci8_test_sql_execute($c, $stmtarray);
26
27// Run Test
28
29echo "Test 1\n";
30
31if (!($s = oci_parse($c, 'select * from fetch_object_2_tab order by 1'))) {
32    die("oci_parse(select) failed!\n");
33}
34
35if (!oci_execute($s)) {
36    die("oci_execute(select) failed!\n");
37}
38
39while ($row = oci_fetch_object($s)) {
40    var_dump($row);
41}
42
43echo "Test 2\n";
44
45if (!($s = oci_parse($c, 'select * from fetch_object_2_tab order by 1'))) {
46    die("oci_parse(select) failed!\n");
47}
48
49if (!oci_execute($s)) {
50    die("oci_execute(select) failed!\n");
51}
52
53while ($row = oci_fetch_object($s)) {
54    echo $row->COL1 . "\n";
55    echo $row->COL2->load() . "\n";
56    echo $row->COL3 . "\n";
57}
58
59// Clean up
60
61$stmtarray = array(
62    "drop table fetch_object_2_tab"
63);
64
65oci8_test_sql_execute($c, $stmtarray);
66
67?>
68--EXPECTF--
69Test 1
70object(stdClass)#%d (3) {
71  ["COL1"]=>
72  string(3) "123"
73  ["COL2"]=>
74  object(OCILob)#%d (1) {
75    ["descriptor"]=>
76    resource(%d) of type (oci8 descriptor)
77  }
78  ["COL3"]=>
79  string(11) "1 more text"
80}
81object(stdClass)#%d (3) {
82  ["COL1"]=>
83  string(3) "456"
84  ["COL2"]=>
85  object(OCILob)#%d (1) {
86    ["descriptor"]=>
87    resource(%d) of type (oci8 descriptor)
88  }
89  ["COL3"]=>
90  NULL
91}
92object(stdClass)#%d (3) {
93  ["COL1"]=>
94  string(3) "789"
95  ["COL2"]=>
96  object(OCILob)#%d (1) {
97    ["descriptor"]=>
98    resource(%d) of type (oci8 descriptor)
99  }
100  ["COL3"]=>
101  string(11) "3 more text"
102}
103Test 2
104123
1051st row col2 string
1061 more text
107456
1082nd row col2 string
109
110789
1113rd row col2 string
1123 more text
113