Skip to content

Commit e6b360b

Browse files
committed
Promote mysqli warnings to exceptions
1 parent 019e8d4 commit e6b360b

File tree

96 files changed

+850
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+850
-522
lines changed

ext/mysqli/php_mysqli_structs.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,26 +247,26 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
247247
MYSQLI_RESOURCE *my_res; \
248248
mysqli_object *intern = Z_MYSQLI_P(__id); \
249249
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\
250-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));\
251-
RETURN_FALSE;\
250+
zend_throw_error(NULL, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));\
251+
RETURN_THROWS();\
252252
}\
253253
__ptr = (__type)my_res->ptr; \
254254
if (__check && my_res->status < __check) { \
255-
php_error_docref(NULL, E_WARNING, "invalid object or resource %s\n", ZSTR_VAL(intern->zo.ce->name)); \
256-
RETURN_FALSE;\
255+
zend_throw_error(NULL, "invalid object or resource %s", ZSTR_VAL(intern->zo.ce->name)); \
256+
RETURN_THROWS();\
257257
}\
258258
}
259259

260260
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
261261
{ \
262262
MYSQLI_RESOURCE *my_res; \
263263
if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
264-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));\
265-
return;\
266-
}\
264+
zend_throw_error(NULL, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));\
265+
return;\
266+
}\
267267
__ptr = (__type)my_res->ptr; \
268268
if (__check && my_res->status < __check) { \
269-
php_error_docref(NULL, E_WARNING, "invalid object or resource %s\n", ZSTR_VAL(intern->zo.ce->name)); \
269+
zend_throw_error(NULL, "invalid object or resource %s", ZSTR_VAL(intern->zo.ce->name)); \
270270
return;\
271271
}\
272272
}
@@ -276,8 +276,8 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
276276
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
277277
if (!(__ptr)->mysql) { \
278278
mysqli_object *intern = Z_MYSQLI_P(__id); \
279-
php_error_docref(NULL, E_WARNING, "invalid object or resource %s\n", ZSTR_VAL(intern->zo.ce->name)); \
280-
RETURN_NULL(); \
279+
zend_throw_error(NULL, "invalid object or resource %s", ZSTR_VAL(intern->zo.ce->name)); \
280+
RETURN_THROWS(); \
281281
} \
282282
}
283283

@@ -286,8 +286,8 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
286286
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
287287
if (!(__ptr)->stmt) { \
288288
mysqli_object *intern = Z_MYSQLI_P(__id); \
289-
php_error_docref(NULL, E_WARNING, "invalid object or resource %s\n", ZSTR_VAL(intern->zo.ce->name)); \
290-
RETURN_NULL();\
289+
zend_throw_error(NULL, "invalid object or resource %s", ZSTR_VAL(intern->zo.ce->name)); \
290+
RETURN_THROWS();\
291291
} \
292292
}
293293

ext/mysqli/tests/bug36802.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ Bug #36802 (crashes with with mysqli_set_charset())
2424
/* following operations should work */
2525
$x[2] = ($mysql->client_version > 0);
2626
$x[3] = $mysql->errno;
27-
$mysql->close();
27+
28+
try {
29+
$mysql->close();
30+
} catch (Error $exception) {
31+
echo $exception->getMessage() . "\n";
32+
}
2833

2934
var_dump($x);
3035
?>
3136
--EXPECT--
37+
invalid object or resource mysqli
3238
array(4) {
3339
[0]=>
3440
bool(false)

ext/mysqli/tests/bug73462.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ require_once('skipifconnectfailure.inc');
1919

2020
/* Failed connection to invalid host */
2121
$mysql_2 = @new mysqli(' !!! invalid !!! ', $user, $passwd, $db);
22-
@$mysql_2->close();
22+
try {
23+
$mysql_2->close();
24+
} catch (Error $exception) {
25+
echo $exception->getMessage() . "\n";
26+
}
2327

2428
/* Re-use persistent connection */
2529
$mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db);
@@ -38,4 +42,5 @@ require_once('skipifconnectfailure.inc');
3842
print "done!";
3943
?>
4044
--EXPECT--
45+
Couldn't fetch mysqli
4146
done!

ext/mysqli/tests/bug75448.phpt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ require_once('skipifconnectfailure.inc');
1111
require_once 'connect.inc';
1212
$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
1313
mysqli_close($link);
14-
$stmt = mysqli_prepare($link, 'SELECT VERSION()');
15-
var_dump($stmt);
16-
?>
17-
--EXPECTF--
18-
Warning: mysqli_prepare(): Couldn't fetch mysqli in %s on line %d
19-
bool(false)
14+
15+
try {
16+
mysqli_prepare($link, 'SELECT VERSION()');
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
20+
--EXPECT--
21+
Couldn't fetch mysqli

ext/mysqli/tests/mysqli_affected_rows.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ mysqli_affected_rows()
110110

111111
mysqli_close($link);
112112

113-
if (false !== ($tmp = @mysqli_affected_rows($link)))
114-
printf("[033] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
113+
try {
114+
mysqli_affected_rows($link);
115+
} catch (Error $exception) {
116+
echo $exception->getMessage() . "\n";
117+
}
115118

116119
print "done!";
117120
?>
@@ -120,4 +123,5 @@ mysqli_affected_rows()
120123
require_once("clean_table.inc");
121124
?>
122125
--EXPECT--
126+
Couldn't fetch mysqli
123127
done!

ext/mysqli/tests/mysqli_autocommit.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,17 @@ mysqli_autocommit()
122122

123123
mysqli_close($link);
124124

125-
if (false !== ($tmp = @mysqli_autocommit($link, false)))
126-
printf("[033] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
125+
try {
126+
mysqli_autocommit($link, false);
127+
} catch (Error $exception) {
128+
echo $exception->getMessage() . "\n";
129+
}
127130

128131
print "done!";
129-
?>
130132
--CLEAN--
131133
<?php
132134
require_once("clean_table.inc");
133135
?>
134136
--EXPECT--
137+
Couldn't fetch mysqli
135138
done!

ext/mysqli/tests/mysqli_autocommit_oo.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ mysqli->autocommit()
124124

125125
$mysqli->close();
126126

127-
if (false !== ($tmp = @$mysqli->autocommit( false)))
128-
printf("[030] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
127+
try {
128+
$mysqli->autocommit(false);
129+
} catch (Error $exception) {
130+
echo $exception->getMessage() . "\n";
131+
}
129132

130133
print "done!";
131134
?>
@@ -134,4 +137,5 @@ mysqli->autocommit()
134137
require_once("clean_table.inc");
135138
?>
136139
--EXPECT--
140+
Couldn't fetch my_mysqli
137141
done!

ext/mysqli/tests/mysqli_change_user.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ require_once('skipifconnectfailure.inc');
8787

8888
mysqli_close($link);
8989

90-
if (false !== ($tmp = @mysqli_change_user($link, $user, $passwd, $db)))
91-
printf("[018] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
90+
try {
91+
mysqli_change_user($link, $user, $passwd, $db);
92+
} catch (Error $exception) {
93+
echo $exception->getMessage() . "\n";
94+
}
9295

9396
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
9497
printf("[019] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
@@ -127,4 +130,5 @@ require_once('skipifconnectfailure.inc');
127130
print "done!";
128131
?>
129132
--EXPECT--
133+
Couldn't fetch mysqli
130134
done!

ext/mysqli/tests/mysqli_character_set_name.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ require_once('skipifconnectfailure.inc');
5050

5151
mysqli_close($link);
5252

53-
if (false !== ($tmp = @mysqli_character_set_name($link)))
54-
printf("[013] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
53+
try {
54+
mysqli_character_set_name($link);
55+
} catch (Error $exception) {
56+
echo $exception->getMessage() . "\n";
57+
}
5558

5659
print "done!";
57-
?>
5860
--EXPECT--
61+
Couldn't fetch mysqli
5962
done!

ext/mysqli/tests/mysqli_character_set_name_oo.phpt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,20 @@ mysqli_chararcter_set_name(), mysql_client_encoding() [alias]
5454

5555
$mysqli->close();
5656

57-
if (false !== ($tmp = @$mysqli->character_set_name()))
58-
printf("[013] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
57+
try {
58+
$mysqli->character_set_name();
59+
} catch (Error $exception) {
60+
echo $exception->getMessage() . "\n";
61+
}
5962

60-
/* Make sure that the function alias exists */
61-
if (false !== ($tmp = @$mysqli->character_set_name()))
62-
printf("[014] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
63+
try {
64+
$mysqli->character_set_name();
65+
} catch (Error $exception) {
66+
echo $exception->getMessage() . "\n";
67+
}
6368

6469
print "done!";
65-
?>
6670
--EXPECT--
71+
Couldn't fetch my_mysqli
72+
Couldn't fetch my_mysqli
6773
done!

ext/mysqli/tests/mysqli_close.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ require_once('skipifconnectfailure.inc');
1818
if (true !== $tmp)
1919
printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
2020

21-
if (false !== ($tmp = @mysqli_query($link, "SELECT 1")))
22-
printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
21+
try {
22+
mysqli_query($link, "SELECT 1");
23+
} catch (Error $exception) {
24+
echo $exception->getMessage() . "\n";
25+
}
2326

2427
print "done!";
25-
?>
2628
--EXPECT--
29+
Couldn't fetch mysqli
2730
done!

ext/mysqli/tests/mysqli_close_oo.phpt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ require_once('skipifconnectfailure.inc');
2121
if (true !== $tmp)
2222
printf("[003] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
2323

24-
if (false !== ($tmp = @$mysqli->close()))
25-
printf("[004] Expecting false got %s/%s\n", gettype($tmp), $tmp);
24+
try {
25+
$mysqli->close();
26+
} catch (Error $exception) {
27+
echo $exception->getMessage() . "\n";
28+
}
2629

27-
if (false !== ($tmp = @$mysqli->query("SELECT 1")))
28-
printf("[005] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
30+
try {
31+
$mysqli->query("SELECT 1");
32+
} catch (Error $exception) {
33+
echo $exception->getMessage() . "\n";
34+
}
2935

3036
print "done!";
3137
?>
3238
--EXPECT--
39+
Couldn't fetch my_mysqli
40+
Couldn't fetch my_mysqli
3341
done!

ext/mysqli/tests/mysqli_commit.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ if (!have_innodb($link))
5252

5353
mysqli_close($link);
5454

55-
if (false !== ($tmp = @mysqli_commit($link)))
56-
printf("[014] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
55+
try {
56+
mysqli_commit($link);
57+
} catch (Error $exception) {
58+
echo $exception->getMessage() . "\n";
59+
}
5760

5861
print "done!";
5962
?>
@@ -62,4 +65,5 @@ if (!have_innodb($link))
6265
require_once("clean_table.inc");
6366
?>
6467
--EXPECT--
68+
Couldn't fetch mysqli
6569
done!

ext/mysqli/tests/mysqli_commit_oo.phpt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ if (!have_innodb($link))
2121
$link = NULL;
2222

2323
$mysqli = new mysqli();
24-
if (false !== ($tmp = @$mysqli->commit())) {
25-
printf("[013] Expecting false got %s/%s\n", gettype($tmp), $tmp);
26-
}
24+
try {
25+
$mysqli->commit();
26+
} catch (Error $exception) {
27+
echo $exception->getMessage() . "\n";
28+
}
2729

2830
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
2931
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
@@ -90,20 +92,23 @@ if (!have_innodb($link))
9092

9193
$mysqli->close();
9294

93-
if (false !== ($tmp = @$mysqli->commit())) {
94-
printf("[017] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
95-
}
95+
try {
96+
$mysqli->commit();
97+
} catch (Error $exception) {
98+
echo $exception->getMessage() . "\n";
99+
}
96100

97101
print "done!";
98-
?>
99102
--CLEAN--
100103
<?php
101104
require_once("clean_table.inc");
102105
?>
103106
--EXPECTF--
107+
invalid object or resource mysqli
104108
Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
105109

106110
Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
107111

108112
Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
113+
invalid object or resource mysqli
109114
done!

ext/mysqli/tests/mysqli_connect_oo.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ require_once('skipifconnectfailure.inc');
5959
// We had long discussions on this and found that the ext/mysqli API as
6060
// such is broken. As we can't fix it, we document how it has behaved from
6161
// the first day on. And that's: no connection.
62-
if (false !== ($tmp = @$mysqli->query('SELECT 1'))) {
63-
printf("[013] There shall be no connection!\n");
64-
$mysqli->close();
65-
}
62+
try {
63+
$mysqli->query('SELECT 1');
64+
} catch (Error $exception) {
65+
echo $exception->getMessage() . "\n";
66+
}
6667
}
6768

6869
if ($IS_MYSQLND) {
@@ -147,6 +148,7 @@ require_once('skipifconnectfailure.inc');
147148
print "done!";
148149
?>
149150
--EXPECTF--
151+
invalid object or resource mysqli
150152
Warning: mysqli::__construct(): (%s/%d): Access denied for user '%sunknown%s'@'%s' (using password: %s) in %s on line %d
151153
... and now Exceptions
152154
Access denied for user '%s'@'%s' (using password: %s)

ext/mysqli/tests/mysqli_data_seek.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ require_once('skipifconnectfailure.inc');
4444

4545
mysqli_free_result($res);
4646

47-
if (false !== ($tmp = mysqli_data_seek($res, 1)))
48-
printf("[013] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
47+
try {
48+
mysqli_data_seek($res, 1);
49+
} catch (Error $exception) {
50+
echo $exception->getMessage() . "\n";
51+
}
4952

5053
mysqli_close($link);
5154

@@ -57,6 +60,5 @@ require_once('skipifconnectfailure.inc');
5760
?>
5861
--EXPECTF--
5962
Warning: mysqli_data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
60-
61-
Warning: mysqli_data_seek(): Couldn't fetch mysqli_result in %s on line %d
63+
Couldn't fetch mysqli_result
6264
done!

0 commit comments

Comments
 (0)