#49298 [Opn->Csd]: mysqli_get_warnings isn't much use
| From: | vrana@php.net | Date: | Fri, 13 Nov 2009 23:01:03 +0000 |
| Subject: | #49298 [Opn->Csd]: mysqli_get_warnings isn't much use | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3156@lists.php.net to get a copy of this message | ||
ID: 49298
Updated by: vrana@php.net
Reported By: marcus at synchromedia dot co dot uk
-Status: Open
+Status: Closed
Bug Type: Documentation problem
PHP Version: 5.3.0
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
I've added the mysqli_warning class to the manual.
Previous Comments:
------------------------------------------------------------------------
[2009-11-13 23:00:18] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=290722
Log: Document mysqli_warning (bug #49298)
------------------------------------------------------------------------
[2009-08-19 21:13:09] marcus at synchromedia dot co dot uk
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.
------------------------------------------------------------------------
[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