* Minor TOS change
[specialops2.git] / lib / class.debugmysqli.php
blobf48144cf92a94f05799ab088f87af8321d3779fc
1 <?php
2 /**
3 * Debug MySQLi class
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://../COPYING
7 * @version $Id$
8 */
9 class debugmysqli extends so2mysqli
11 public $c; // query counter
12 private $d = false; // debug next query flag
14 public function query($q)
16 if ( $this->d ) {
17 mysqli_report(MYSQLI_REPORT_ALL);
20 $result = parent::query($q);
22 if ( $this->error ) {
23 throw new RuntimeException("MySQLi query() error!\n".$this->error."\nQuery given was: \n".$q, E_USER_ERROR);
26 if ( $this->warning_count ) {
27 $result2 = $this->query('SHOW WARNINGS');
28 $out = '';
30 while ( $row = $result2->fetch_row() ) {
31 $out .= vsprintf("%s #%s: %s\n", $row);
34 throw new RuntimeException("MySQLi query() warning(s)\n".$out."\nQuery given was: \n".$q, E_USER_WARNING);
37 $this->c++;
39 if ( $this->d ) {
40 $this->d = false;
41 mysqli_report(MYSQLI_REPORT_OFF);
44 return $result;
47 public function prepare($q)
49 $result = parent::prepare($q);
51 if ( $this->error ) {
52 throw new RuntimeException("MySQLi prepare() error\n".$this->error."\nQuery given was: \n".$q, E_USER_ERROR);
55 $this->c++;
57 return $result;
60 public function debugnext()
62 $this->d = true;
66 /**
67 * Make sure mysqli_report setting doesn't linger across requests
69 register_shutdown_function('mysqli_report', MYSQLI_REPORT_OFF);