PHP  
 PHP_5_6
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/mysqli/tests/mysqli_stmt_affected_rows.phpt ('mysqli_stmt_affected_rows()')

Script

1: <?php
2:     
require_once("connect.inc");
3:
4:     
$tmp    NULL;
5:     
$link   NULL;
6:
7:     if (!
is_null($tmp = @mysqli_stmt_affected_rows()))
8:         
printf("[001] Expecting NULL, got %s/%s\n"gettype($tmp), $tmp);
9:
10:     if (!
is_null($tmp = @mysqli_stmt_affected_rows($link)))
11:         
printf("[002] Expecting NULL, got %s/%s\n"gettype($tmp), $tmp);
12:
13:     if (!
$link my_mysqli_connect($host$user$passwd$db$port$socket)) {
14:         
printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
15:             
$host$user$db$port$socket);
16:     }
17:     
$stmt mysqli_stmt_init($link);
18:
19:     if (!
mysqli_stmt_prepare($stmt'DROP TABLE IF EXISTS test') ||
20:         !
mysqli_stmt_execute($stmt)) {
21:         
printf("[003] Failed to drop old test table: [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
22:     }
23:
24:     if (!
mysqli_stmt_prepare($stmt'CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' $engine) ||
25:         !
mysqli_stmt_execute($stmt)) {
26:         
printf("[004] Failed to create test table: [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
27:     }
28:
29:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
30:         
printf("[005] Expecting int/0, got %s/'%s'\n"gettype($tmp), $tmp);
31:
32:     
mysqli_stmt_close($stmt);
33:     
$stmt mysqli_stmt_init($link);
34:
35:     if (!
mysqli_stmt_prepare($stmt"INSERT INTO test(id, label) VALUES (1, 'a')") ||
36:         !
mysqli_stmt_execute($stmt))
37:         
printf("[006] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
38:
39:     
mysqli_stmt_close($stmt);
40:     
$stmt mysqli_stmt_init($link);
41:
42:     if (!
mysqli_stmt_prepare($stmt"INSERT INTO test(id, label) VALUES (100, 'z')") ||
43:         !
mysqli_stmt_execute($stmt))
44:         
printf("[007] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
45:
46:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
47:         
printf("[008] Expecting int/1, got %s/%s\n"gettype($tmp), $tmp);
48:
49:     
mysqli_stmt_close($stmt);
50:     
$stmt mysqli_stmt_init($link);
51:
52:     if (!
mysqli_stmt_prepare($stmt"INSERT INTO test(id, label) VALUES (100, 'z')") ||
53:         !
mysqli_stmt_execute($stmt))
54:         
// NOTE: the error message varies with the MySQL Server version, dump only the error code!
55:         
printf("[009] [%d] (error message varies with the MySQL Server version, check the error code)\n"mysqli_stmt_errno($stmt));
56:
57:     
/* an error occurred: affected rows should return -1 */
58:     
if (-!== ($tmp mysqli_stmt_affected_rows($stmt)))
59:         
printf("[010] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
60:
61:     
mysqli_stmt_close($stmt);
62:     
$stmt mysqli_stmt_init($link);
63:
64:     if (!
mysqli_stmt_prepare($stmt"INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4") ||
65:         !
mysqli_stmt_execute($stmt))
66:         
printf("[011] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
67:
68:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
69:         
printf("[012] Expecting int/2, got %s/%s\n"gettype($tmp), $tmp);
70:
71:     
mysqli_stmt_close($stmt);
72:     
$stmt mysqli_stmt_init($link);
73:
74:     if (!
mysqli_stmt_prepare($stmt"INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')") ||
75:         !
mysqli_stmt_execute($stmt))
76:         
printf("[013] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
77:
78:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
79:         
printf("[014] Expecting int/2, got %s/%s\n"gettype($tmp), $tmp);
80:
81:     
mysqli_stmt_close($stmt);
82:     
$stmt mysqli_stmt_init($link);
83:
84:     if (!
mysqli_stmt_prepare($stmt"INSERT IGNORE INTO test(id, label) VALUES (1, 'a')") ||
85:         !
mysqli_stmt_execute($stmt))
86:         
printf("[015] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
87:
88:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
89:         
printf("[016] Expecting int/1, got %s/%s\n"gettype($tmp), $tmp);
90:
91:     if (!(
$res mysqli_query($link"SELECT count(id) AS num FROM test")) ||
92:         !(
$tmp mysqli_fetch_assoc($res)))
93:         
printf("[017] [%d] %s\n"mysqli_error($link), mysqli_error($link));
94:     
$num = (int)$tmp['num'];
95:     
mysqli_free_result($res);
96:
97:     
mysqli_stmt_close($stmt);
98:     
$stmt mysqli_stmt_init($link);
99:
100:     if (!
mysqli_stmt_prepare($stmt"INSERT INTO test(id, label) SELECT id + 10, label FROM test") ||
101:         !
mysqli_stmt_execute($stmt))
102:         
printf("[018] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
103:
104:     if (
$num !== ($tmp mysqli_stmt_affected_rows($stmt)))
105:         
printf("[019] Expecting int/%d, got %s/%s\n"$numgettype($tmp), $tmp);
106:
107:     
mysqli_stmt_close($stmt);
108:     
$stmt mysqli_stmt_init($link);
109:
110:     if (!
mysqli_stmt_prepare($stmt"REPLACE INTO test(id, label) values (4, 'd')") ||
111:         !
mysqli_stmt_execute($stmt))
112:         
printf("[020] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
113:
114:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
115:         
printf("[021] Expecting int/2, got %s/%s\n"gettype($tmp), $tmp);
116:
117:     
mysqli_stmt_close($stmt);
118:     
$stmt mysqli_stmt_init($link);
119:
120:     if (!
mysqli_stmt_prepare($stmt"REPLACE INTO test(id, label) values (5, 'e')") ||
121:         !
mysqli_stmt_execute($stmt))
122:         
printf("[022] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
123:
124:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
125:         
printf("[023] Expecting int/1, got %s/%s\n"gettype($tmp), $tmp);
126:
127:     
mysqli_stmt_close($stmt);
128:     
$stmt mysqli_stmt_init($link);
129:
130:     if (!
mysqli_stmt_prepare($stmt"UPDATE test SET label = 'a' WHERE id = 2") ||
131:         !
mysqli_stmt_execute($stmt))
132:         
printf("[024] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
133:
134:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
135:         
printf("[025] Expecting int/1, got %s/%s\n"gettype($tmp), $tmp);
136:
137:     if (!
mysqli_stmt_prepare($stmt"UPDATE test SET label = 'a' WHERE id = 2") ||
138:         !
mysqli_stmt_execute($stmt))
139:         
printf("[026] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
140:
141:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
142:         
printf("[027] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
143:
144:     
mysqli_stmt_close($stmt);
145:     
$stmt mysqli_stmt_init($link);
146:
147:     if (!
mysqli_stmt_prepare($stmt"UPDATE test SET label = 'a' WHERE id = 100") ||
148:         !
mysqli_stmt_execute($stmt))
149:         
printf("[028] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
150:
151:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
152:         
printf("[029] Expecting int/1, got %s/%s\n"gettype($tmp), $tmp);
153:
154:     if (!
mysqli_stmt_prepare($stmt'SELECT label FROM test WHERE id = 100') ||
155:         !
mysqli_stmt_execute($stmt))
156:         
printf("[030] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
157:
158:     
/* use it like num_rows */
159:     /* PS are unbuffered, num_rows cannot determine the row count before all rows have been fetched and/or buffered */
160:     
if (-!== ($tmp mysqli_stmt_affected_rows($stmt)))
161:         
printf("[031] Expecting int/-1, got %s/%s\n"gettype($tmp), $tmp);
162:
163:     if (
!== ($tmp mysqli_stmt_num_rows($stmt)))
164:         
printf("[032] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
165:
166:     if (!
mysqli_stmt_store_result($stmt))
167:         
printf("[033] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
168:
169:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
170:         
printf("[034] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
171:
172:     if (
!== ($tmp mysqli_stmt_num_rows($stmt)))
173:         
printf("[035] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
174:
175:     
mysqli_stmt_free_result($stmt);
176:     
mysqli_stmt_close($stmt);
177:     
$stmt mysqli_stmt_init($link);
178:
179:     if (!
mysqli_stmt_prepare($stmt'SELECT label FROM test WHERE 1 = 2') ||
180:         !
mysqli_stmt_execute($stmt))
181:         
printf("[036] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
182:
183:     
/* use it like num_rows */
184:     
if (-!== ($tmp mysqli_stmt_affected_rows($stmt)))
185:         
printf("[037] Expecting int/-1, got %s/%s\n"gettype($tmp), $tmp);
186:
187:     if (
true !== ($tmp mysqli_stmt_store_result($stmt)))
188:         
printf("[038] Expecting boolean/true, got %s\%s\n"gettype($tmp), $tmp);
189:
190:     if (
!== ($tmp mysqli_stmt_num_rows($stmt)))
191:         
printf("[039] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
192:
193:     if (
!== ($tmp mysqli_stmt_affected_rows($stmt)))
194:         
printf("[040] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
195:
196:     
/* try to use stmt_affected_rows like stmt_num_rows */
197:     /* stmt_affected_rows is not really meant for SELECT! */
198:     
if (mysqli_stmt_prepare($stmt'SELECT unknown_column FROM this_table_does_not_exist') ||
199:         
mysqli_stmt_execute($stmt))
200:         
printf("[041] The invalid SELECT statement is issued on purpose\n");
201:
202:     if (-
!== ($tmp mysqli_stmt_affected_rows($stmt)))
203:         
printf("[042] Expecting int/-1, got %s/%s\n"gettype($tmp), $tmp);
204:
205:     if (
$IS_MYSQLND) {
206:         if (
false !== ($tmp mysqli_stmt_store_result($stmt)))
207:             
printf("[043] Expecting boolean/false, got %s\%s\n"gettype($tmp), $tmp);
208:     } else {
209:         if (
true !== ($tmp mysqli_stmt_store_result($stmt)))
210:             
printf("[043] Libmysql does not care if the previous statement was bogus, expecting boolean/true, got %s\%s\n"gettype($tmp), $tmp);
211:     }
212:
213:     if (
!== ($tmp mysqli_stmt_num_rows($stmt)))
214:         
printf("[044] Expecting int/0, got %s/%s\n"gettype($tmp), $tmp);
215:
216:     if (-
!== ($tmp mysqli_stmt_affected_rows($stmt)))
217:         
printf("[045] Expecting int/-1, got %s/%s\n"gettype($tmp), $tmp);
218:
219:     
mysqli_stmt_close($stmt);
220:     
$stmt mysqli_stmt_init($link);
221:
222:     if (!
mysqli_stmt_prepare($stmt"DROP TABLE IF EXISTS test") ||
223:         !
mysqli_stmt_execute($stmt))
224:         
printf("[046] [%d] %s\n"mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
225:
226:     
mysqli_stmt_close($stmt);
227:
228:     if (!
is_null($tmp mysqli_stmt_affected_rows($stmt)))
229:         
printf("[047] Expecting NULL, got %s/%s\n"gettype($tmp), $tmp);
230:
231:     
mysqli_close($link);
232:
233:     print 
"done!";
234:
?>
235:

Expected

[009] [%d] (error message varies with the MySQL Server version, check the error code)

Warning: mysqli_stmt_affected_rows(): Couldn't fetch mysqli_stmt in %s on line %d
done!

Output

[009] [1062] (error message varies with the MySQL Server version, check the error code)
Out of memory

Diff

002+ Out of memory
002- 
003- Warning: mysqli_stmt_affected_rows(): Couldn't fetch mysqli_stmt in %s on line %d
004- done!

 

Generated at Mon, 27 Nov 2017 05:04:32 +0000 (16 days ago)

Copyright © 2005-2017 The PHP Group
All rights reserved.