Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are 3 types of errors:</p> <ol> <li><p>System errors, such as warnings or fatal errors raised by PHP. 404 errors are also in this category.</p></li> <li><p>Database errors by a malformed or failed query or database connection.</p></li> <li>Logical errors such as when something went wrong in the internal working of your application not related to a server or database. For example if you expected a certain file to be in a given folder, but it wasn't.</li> </ol> <p>The best way to create an <code>ErrorHandler</code> class that handles all three types of errors. For system errors, you would use <code>set_error_handler</code> or read up on one of the online tutorials such as <a href="http://www.w3schools.com/PHP/php_ref_error.asp" rel="nofollow noreferrer">this one</a>. </p> <p>For database, I suggest using a centralized Database class which handles all the queries. Use something like this:</p> <pre><code>$result=mysql_query($sql); if (! $result) { $ErrorHandler-&gt;dbError(mysql_error(), $sql); } </code></pre> <p>For logical errors, such as the error of not finding an expected file or database record, you would call up the same ErrorHandler class and do something like:</p> <pre><code>if ($logicalError) { $ErrorHandler-&gt;appError('Something bad happened',__LINE__, __FILE__); $ErrorHandler-&gt;showAppErrorPage(); } </code></pre> <p>Here the <code>__FILE__</code> and <code>__LINE__</code> constants will give exactly the location where this error occurred. Read up on them on the <a href="http://php.net" rel="nofollow noreferrer">php.net</a> site.</p> <p>Your <code>ErrorHandler</code> class can log all errors to a log file, email you, or even SMS/Text you on your mobile. It could also be used to redirect the user to an error page.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload