xref: /PHP-8.0/ext/oci8/tests/fetch_object_2.phpt (revision ff66e494)
1--TEST--
2oci_fetch_object() with CLOB and NULL
3--SKIPIF--
4<?php
5$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
6require(__DIR__.'/skipif.inc');
7?>
8--FILE--
9<?php
10
11require(__DIR__.'/connect.inc');
12
13// Initialization
14
15$stmtarray = array(
16    "drop table fetch_object_2_tab",
17    "create table fetch_object_2_tab (col1 number, col2 CLOB, col3 varchar2(15))",
18    "insert into fetch_object_2_tab values (123, '1st row col2 string', '1 more text')",
19    "insert into fetch_object_2_tab values (456, '2nd row col2 string', NULL)",
20    "insert into fetch_object_2_tab values (789, '3rd row col2 string', '3 more text')",
21);
22
23oci8_test_sql_execute($c, $stmtarray);
24
25// Run Test
26
27echo "Test 1\n";
28
29if (!($s = oci_parse($c, 'select * from fetch_object_2_tab order by 1'))) {
30    die("oci_parse(select) failed!\n");
31}
32
33if (!oci_execute($s)) {
34    die("oci_execute(select) failed!\n");
35}
36
37while ($row = oci_fetch_object($s)) {
38    var_dump($row);
39}
40
41echo "Test 2\n";
42
43if (!($s = oci_parse($c, 'select * from fetch_object_2_tab order by 1'))) {
44    die("oci_parse(select) failed!\n");
45}
46
47if (!oci_execute($s)) {
48    die("oci_execute(select) failed!\n");
49}
50
51while ($row = oci_fetch_object($s)) {
52    echo $row->COL1 . "\n";
53    echo $row->COL2->load() . "\n";
54    echo $row->COL3 . "\n";
55}
56
57// Clean up
58
59$stmtarray = array(
60    "drop table fetch_object_2_tab"
61);
62
63oci8_test_sql_execute($c, $stmtarray);
64
65?>
66--EXPECTF--
67Test 1
68object(stdClass)#%d (3) {
69  ["COL1"]=>
70  string(3) "123"
71  ["COL2"]=>
72  object(OCILob)#%d (1) {
73    ["descriptor"]=>
74    resource(%d) of type (oci8 descriptor)
75  }
76  ["COL3"]=>
77  string(11) "1 more text"
78}
79object(stdClass)#%d (3) {
80  ["COL1"]=>
81  string(3) "456"
82  ["COL2"]=>
83  object(OCILob)#%d (1) {
84    ["descriptor"]=>
85    resource(%d) of type (oci8 descriptor)
86  }
87  ["COL3"]=>
88  NULL
89}
90object(stdClass)#%d (3) {
91  ["COL1"]=>
92  string(3) "789"
93  ["COL2"]=>
94  object(OCILob)#%d (1) {
95    ["descriptor"]=>
96    resource(%d) of type (oci8 descriptor)
97  }
98  ["COL3"]=>
99  string(11) "3 more text"
100}
101Test 2
102123
1031st row col2 string
1041 more text
105456
1062nd row col2 string
107
108789
1093rd row col2 string
1103 more text
111