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