xref: /PHP-8.3/ext/oci8/tests/num.phpt (revision a53e5617)
1--TEST--
2oci_num_*() family
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11
12require __DIR__.'/connect.inc';
13
14// Initialize
15
16$stmtarray = array(
17    "drop table num_tab",
18    "create table num_tab (id number, value number)",
19);
20
21oci8_test_sql_execute($c, $stmtarray);
22
23// Run Test
24echo "Test 1\n";
25$insert_sql = "insert into num_tab (id, value) values (1,1)";
26if (!($s = oci_parse($c, $insert_sql))) {
27    die("oci_parse(insert) failed!\n");
28}
29
30var_dump(oci_num_rows($s));
31var_dump(oci_num_fields($s));
32
33for ($i = 0; $i<3; $i++) {
34  if (!oci_execute($s)) {
35    die("oci_execute(insert) failed!\n");
36  }
37}
38
39echo "Test 2\n";
40var_dump(oci_num_rows($s));
41var_dump(oci_num_fields($s));
42
43if (!oci_commit($c)) {
44  die("oci_commit() failed!\n");
45}
46
47echo "Test 3\n";
48var_dump(oci_num_rows($s));
49var_dump(oci_num_fields($s));
50
51// All rows
52$select_sql = "select * from num_tab";
53
54if (!($s = oci_parse($c, $select_sql))) {
55  die("oci_parse(select) failed!\n");
56}
57
58echo "Test 4a\n";
59var_dump(oci_num_rows($s));
60var_dump(oci_num_fields($s));
61
62if (!oci_execute($s)) {
63  die("oci_execute(select) failed!\n");
64}
65
66echo "Test 4b\n";
67var_dump(oci_num_rows($s));
68var_dump(oci_num_fields($s));
69
70
71if (oci_fetch_all($s,$r) === false) {
72  die("oci_fetch_all(select) failed!\n");
73}
74
75echo "Test 4c\n";
76var_dump(oci_num_rows($s));
77var_dump(oci_num_fields($s));
78
79// One row
80$select_sql = "SELECT id, value FROM num_tab WHERE ROWNUM < 2";
81
82if (!($s = oci_parse($c, $select_sql))) {
83  die("oci_parse(select) failed!\n");
84}
85
86if (!oci_execute($s)) {
87  die("oci_execute(select) failed!\n");
88}
89
90if (oci_fetch_all($s,$r) === false) {
91  die("oci_fetch_all(select) failed!\n");
92}
93
94echo "Test 5\n";
95var_dump(oci_num_rows($s));
96var_dump(oci_num_fields($s));
97
98// No rows
99$select_sql = "select id from num_tab where 1=0";
100
101if (!($s = oci_parse($c, $select_sql))) {
102  die("oci_parse(select) failed!\n");
103}
104
105if (!oci_execute($s)) {
106  die("oci_execute(select) failed!\n");
107}
108
109if (oci_fetch_all($s,$r) === false) {
110  die("oci_fetch_all(select) failed!\n");
111}
112
113echo "Test 6\n";
114var_dump(oci_num_rows($s));
115var_dump(oci_num_fields($s));
116
117$delete_sql = "delete from num_tab";
118
119if (!($s = oci_parse($c, $delete_sql))) {
120    die("oci_parse(delete) failed!\n");
121}
122
123if (!oci_execute($s)) {
124    die("oci_execute(delete) failed!\n");
125}
126
127echo "Test 7a\n";
128var_dump(oci_num_rows($s));
129var_dump(oci_num_fields($s));
130
131oci_commit($c);
132
133// Cleanup
134
135$stmtarray = array(
136    "drop table num_tab"
137);
138
139oci8_test_sql_execute($c, $stmtarray);
140
141echo "Done\n";
142
143?>
144--EXPECT--
145Test 1
146int(0)
147int(0)
148Test 2
149int(1)
150int(0)
151Test 3
152int(1)
153int(0)
154Test 4a
155int(0)
156int(0)
157Test 4b
158int(0)
159int(2)
160Test 4c
161int(3)
162int(2)
163Test 5
164int(1)
165int(2)
166Test 6
167int(0)
168int(1)
169Test 7a
170int(3)
171int(0)
172Done
173