note 93021 modified in mysqli.get-warnings by danbrown

From: Date: Wed, 19 Aug 2009 22:03:38 +0000
Subject: note 93021 modified in mysqli.get-warnings by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159668@lists.php.net to get a copy of this message
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()); } ?> --was-- 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(); } } ?> This is a pretty rubbish interface - it's clearly a kind of half-baked iterable / traversable, but doesn't advertise those interfaces. It's actually more code than doing and processing a SHOW WARNINGS query manually! http://php.net/manual/en/mysqli.get-warnings.php

« previous php.notes (#159668) next »