ID: 49298
User updated by: marcus at synchromedia dot co dot uk
Reported By: marcus at synchromedia dot co dot uk
Status: Open
Bug Type: MySQLi related
PHP Version: 5.3.0
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2009-08-19 19:26:28] marcus at synchromedia dot co dot uk
Sorry, misnamed function in title
------------------------------------------------------------------------
[2009-08-19 14:15:26] 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)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49298&edit=1