Witajcie. Czy jest jakaś funkcja, opcja, dzięki której pod koniec działania skryptu zobaczę, czy którekolwiek z zapytań zwróciło błąd?
Ewentualnie czy jest jakaś inna opcja żeby zobaczyć czy kod php nie wywołuje żadnych błędów?
<?php function begin() { $time = $time[1] + $time[0]; return $time; } function finish( $time1 ) { $time = $time[1] + $time[0]; $time2 = $time; $total = ($time2 - $time1); return $total; } function log_exception( $e ) { $log.= 'Wywolanie z adresu: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n"; $log.= 'Plik: ' . $e->getFile() . "\n"; $log.= 'Linia: ' . ($e->getLine()-1) . "\n"; $log.= 'Komunikat: ' . ( !$e->getMessage() ? 'Brak wymaganego pliku' : $e->getMessage() ) . "\n"; $log.= "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"; return false; } } return true; } function err( $e ) { if ( function_exists('log_exception') ) { log_exception( $e ); } $err = '<style type="text/css">' .'<!--' .'dl, dt, dd {' .'display: block; margin: 0; padding: 0;' .'}' .'dt {' .'float: left;' .'font-weight: bold;' .'}' .'//-->' .'</style>' .'<h1>Plik: '.$e->getFile().'</h1>' .'<h2>Bład lini: '.($e->getLine()-1).'</h2>' .'<dl>' .'<dt>Komunikat: </dt>' .'<dd>' .( !$e->getMessage() ? 'Brak wymaganego pliku' : $e->getMessage() ) .'</dd>' .'</dl>'; } /** * Klasa obslugi bazy danych */ class db extends mysqli { /** * Przechowuje zapytania * * @var string */ public $query = false; /** * Utrzymuje polaczenie * * @var object */ /** * Uruchamia debugera * * @var bool */ private $debug = false; /** * Zlicza ilosc zapytan * * @var int */ private $debugCount = 0; /** * Zlicza wszystkie czasy zapytan * * @var float */ private $debugTime = 0; /** * Kontener na wyliczenia * * @var string */ private $debugHTML = false; private function __construct($host, $user, $pass, $schema, $port) { try { parent::__construct( $host, $user, $pass, $schema ); if ( mysqli_connect_errno() ) { throw new Exception( mysqli_connect_error() ); } /* Ustawienie kodowania */ parent::query('SET NAMES utf8'); parent::query('SET CHARACTER SET utf8'); } catch(Exception $e) { err($e); } } try { if ( !self::$singleton ) { self::$singleton = new db( HOST, USER, PASSWORD, SCHEMA, PORT ); } if ( mysqli_connect_errno() ) { throw new Exception( mysqli_connect_error() ); } return self::$singleton; } catch (Exception $e) { err( $e ); } } public function query( $query ) { try { if( self::$singleton->debug ) { $queryTime = begin(); } $result =& parent::query($query); if( self::$singleton->debug ) { $time = finish($queryTime); self::$singleton->debugHTML.= ' <div style="overflow-x: auto; width: 720px; display: block; margin: 15px auto; background: #eee; border: 3px solid #aaa; color: #000;"> Czas wykonywania: ' . $time . ' <pre style="color: #666;">'. $query .'</pre> </div> '; self::$singleton->debugCount++; self::$singleton->debugTime+= $time; } return $result; } catch (Exception $e) { err( $e ); } } private function debugMSG() { try { $html = "<div id='debugSQL' style='position: absolute; top: 20px; left: 20px; width: 800px; background: #fff; color: #000; border: 5px solid #666; auto; padding: 15px; z-index: 100;'>"; $html.= "<div style='text-align: right;'><a href='java script:;' onclick='document.getElementById(\"debugSQL\").style.display=\"none\";'>zamknij</a></div>"; $html.= "<h1>Debug SQL</h1>"; $html.= "<div>Czas wykonywania: <strong>" . self::$singleton->debugTime . "</strong></div>"; $html.= "<div>W sumie wykonano: <strong>" . self::$singleton->debugCount . "</strong></div><hr />"; $html.= "</div>"; } catch (Exception $e) { err( $e ); } } public function __destruct() { try { if( self::$singleton->debug ) { return self::debugMSG(); } } catch( Exception $e ) { err( $e ); } } } ?>
<?php try { include_once 'db.class.php'; $query = 'SELECT * FROM `tabela`'; if( !$result = db::__connect()->query( $query ) ) { throw new Exception('Blad zapytania SQL'); } while( $row = $result->fetch_assoc() ) { $arr[] = $row; } } catch( Exception $e ) { err( $e ); } ?>