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