php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49298 mysqli_get_warnings isn't much use
Submitted: 2009-08-19 14:15 UTC Modified: 2009-11-13 23:01 UTC
From: marcus at synchromedia dot co dot uk Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.3.0 OS:
Private report: No CVE-ID: None
 [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)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-19 21:13 UTC] 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-11-13 23:00 UTC] 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-11-13 23:01 UTC] vrana@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Oct 17 19:00:01 2025 UTC