xref: /PHP-8.0/ext/oci8/tests/fetch_object.phpt (revision 45475c2e)
1--TEST--
2oci_fetch_object()
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_tab",
17    "create table fetch_object_tab (\"caseSensitive\" number, secondcol varchar2(20), anothercol char(15))",
18    "insert into fetch_object_tab values (123, '1st row col2 string', '1 more text')",
19    "insert into fetch_object_tab values (456, '2nd row col2 string', '2 more text')",
20    "insert into fetch_object_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_tab'))) {
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_tab'))) {
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->caseSensitive . "\n";
53    echo $row->SECONDCOL . "\n";
54    echo $row->ANOTHERCOL . "\n";
55}
56
57echo "Test 3\n";
58
59if (!($s = oci_parse($c, 'select * from fetch_object_tab where rownum < 2 order by "caseSensitive"'))) {
60    die("oci_parse(select) failed!\n");
61}
62
63if (!oci_execute($s)) {
64    die("oci_execute(select) failed!\n");
65}
66
67$row = oci_fetch_object($s);
68echo $row->caseSensitive . "\n";
69echo $row->CASESENSITIVE . "\n";
70
71// Clean up
72
73$stmtarray = array(
74    "drop table fetch_object_tab"
75);
76
77oci8_test_sql_execute($c, $stmtarray);
78
79?>
80--EXPECTF--
81Test 1
82object(stdClass)#1 (3) {
83  ["caseSensitive"]=>
84  string(3) "123"
85  ["SECONDCOL"]=>
86  string(19) "1st row col2 string"
87  ["ANOTHERCOL"]=>
88  string(15) "1 more text    "
89}
90object(stdClass)#2 (3) {
91  ["caseSensitive"]=>
92  string(3) "456"
93  ["SECONDCOL"]=>
94  string(19) "2nd row col2 string"
95  ["ANOTHERCOL"]=>
96  string(15) "2 more text    "
97}
98object(stdClass)#1 (3) {
99  ["caseSensitive"]=>
100  string(3) "789"
101  ["SECONDCOL"]=>
102  string(19) "3rd row col2 string"
103  ["ANOTHERCOL"]=>
104  string(15) "3 more text    "
105}
106Test 2
107123
1081st row col2 string
1091 more text
110456
1112nd row col2 string
1122 more text
113789
1143rd row col2 string
1153 more text
116Test 3
117123
118
119Warning: Undefined property: stdClass::$CASESENSITIVE in %sfetch_object.php on line %d
120
121