|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-19 14:15 UTC] marcus at synchromedia dot co dot uk
Description:
------------
mysqli_get_warnings only ever returns a single warning, even if more
than one is available.
Though its name implies a plural response, it doesn't deliver one.
Reproduce code:
---------------
Do this in a mysql CLI:
CREATE TABLE `blah` (
`x` varchar(100) NOT NULL,
`y` varchar(100) NOT NULL,
`z` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO blah SET z = '1';
Query OK, 1 row affected, 2 warnings (0.00 sec)
mysql> show warnings;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1364 | Field 'x' doesn't have a default value |
| Warning | 1364 | Field 'y' doesn't have a default value |
+---------+------+----------------------------------------+
Now do the same insert from PHP then call mysqli_get_warnings() (approximate code):
mysqli_query($db, "INSERT INTO blah SET z = '1'");
$a = mysqli_get_warnings($db);
var_dump($a);
Expected result:
----------------
I'd want something like this:
array (2) {
object(mysqli_warning)#4 (3) {
["message"]=>
string(38) "Field 'x' doesn't have a default value"
["sqlstate"]=>
string(5) "HY000"
["errno"]=>
int(1364)
},
object(mysqli_warning)#5 (3) {
["message"]=>
string(38) "Field 'y' doesn't have a default value"
["sqlstate"]=>
string(5) "HY000"
["errno"]=>
int(1364)
}
}
Actual result:
--------------
object(mysqli_warning)#4 (3) {
["message"]=>
string(38) "Field 'x' doesn't have a default value"
["sqlstate"]=>
string(5) "HY000"
["errno"]=>
int(1364)
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 05:00:01 2025 UTC |
I've discovered that the mysqli_warning class has a next() method that retrieves the next warning in the instance properties. It can be used like this: $r = mysqli_query($db, 'INSERT INTO blah SET z = '1'); if (mysqli_warning_count($db)) { $e = mysqli_get_warnings($db); do { echo "Warning: $e->errno: $e->message\n"; } while ($e->next()); } I think this is the first time I've ever needed a bottom-tested loop! This looks like half-baked implementation of a traversable interface - could it be finished off? Overall I guess this amounts to a documentation problem, so I've added notes to the appropriate page too.