note 49863 deleted from ref.mysqli by hholzgra

From: Date: Sat, 29 Sep 2007 09:49:28 +0000
Subject: note 49863 deleted from ref.mysqli by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130905@lists.php.net to get a copy of this message
Note Submitter: K dot Londenberg at librics dot de ---- Second part of the mysqli wrapper code since it didn't all get into one note ------ exception.php ------------- <?php class FatalException extends Exception {}; class ErrorException extends Exception {}; class WarningException extends Exception {}; function exceptionErrorHandler($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_ERROR: throw new FatalException($errstr, $errno); break; case E_USER_WARNING: case E_WARNING: throw new WarningException($errstr, $errno); break; case E_USER_NOTICE: //throw new WarningException($errstr, $errno); break; default: echo " - Unknown error - <b>$errstr</b>($errno) <br>"; break; } //return true; } $old_error_handler = null; function install_exception_errorhandler() { global $old_error_handler; $old_error_handler = set_error_handler(exceptionErrorHandler); } function uninstall_exception_errorhandler() { global $old_error_handler; set_error_handler($old_error_handler); $old_error_handler = null; } // returns formatted info-dump of an exception function exception_dump(&$e) { $res = ""; $res .= "<br><h2>".get_class($e)."</h2>\n"; $res .= "<h3>{$e->getMessage()} ({$e->getCode()})</h3>\n\n"; $res .= "file: {$e->getFile()}<br/>\n"; $res .= "line: {$e->getLine()}<br/>\n"; $res .= "<PRE>"; $res .= $e->getTraceAsString(); $res .= "</PRE><br>"; return $res; } ?> ------------------------------------------- Example-Code: ------ example.php ------------------------ <?php require_once('safe_mysqli.php'); try { $mysql = new safe_mysqli('locashost', 'user', 'pass', 'test'); $stmt = $mysql->prepare("SELECT city, city_accented, population, latitude, longitude from world_cities where city like ? order by population desc limit 5"); $stmt->bind_param('s', $a); $stmt->bind_result($city, $city_accented, $population, $latitude, $longitude); foreach ($anfangsbuchstaben as $a) { $stmt->execute(); while ($stmt->fetch()) { echo "<b>$city_accented</b>: pop $population - Lat. $latitude Long. $longitude<br>"; } $stmt->free_result(); } } catch (SQLException $e) { die("SQL Error : ".$e->getSQLError()." in <hr><PRE>".$e->getSQL()."</PRE><hr>"); } catch (DBException $e) { die("Database Error: ". $e->GetMessage()); } catch (Exception $e) { die(exception_dump($e)); } ?> ----------------------------------------- Hope this helps ...

« previous php.notes (#130905) next »