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