PHP Doku:: Get result of SHOW WARNINGS - mysqli.get-warnings.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenMySQL Improved ExtensionThe MySQLi classmysqli::get_warnings -- mysqli_get_warnings

Ein Service von Reinhard Neidl - Webprogrammierung.

The MySQLi class

<<mysqli->server_version -- mysqli_get_server_version

mysqli->info -- mysqli_info>>

mysqli::get_warnings

mysqli_get_warnings

(PHP 5 >= 5.1.0)

mysqli::get_warnings -- mysqli_get_warningsGet result of SHOW WARNINGS

Beschreibung

Objektorientierter Stil

mysqli_warning mysqli::get_warnings ( void )

Prozeduraler Stil

mysqli_warning mysqli_get_warnings ( mysqli $link )
Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
marcus at synchromedia dot co dot uk
19.08.2009 23:02
With a bit of rooting about with reflection, I spotted that the mysqli_warning class has a next() function, so I tried calling it and it does indeed progress through the available warnings! Following on from my earlier example:

<?php
$r
= mysqli_query($db, "INSERT INTO blah SET z = '1'");
$j = mysqli_warning_count($db);
if (
$j > 0) {
   
$e = mysqli_get_warnings($db);
    for (
$i = 0; $i < $j; $i++) {
       
var_dump($e);
       
$e->next();
    }
}
?>

There is a simple way of traversing the warnings:

<?php
$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());
}
?>
marcus at synchromedia dot co dot uk
19.08.2009 16:13
I'm not sure how useful this function is as implemented. Take this example:

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 |
+---------+------+----------------------------------------+

Doing the same from PHP using mysqli_get_warnings(), you get this instead:

object(mysqli_warning)#4 (3) {
  ["message"]=>
  string(38) "Field 'x' doesn't have a default value"
  ["sqlstate"]=>
  string(5) "HY000"
  ["errno"]=>
  int(1364)
}

i.e. it only returns the first warning. I suspect it should return an array of these objects rather than just one. At least you know what the return value looks like now, since the docs don't say!



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)