Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have created my own code to execute MySQL statements and raise exceptions if they fail, including specific exceptions for different causes of failure. One of the most helpful of these is when collisions occur, allowing me to use <code>try..catch</code> blocks and catch <code>DatabaseCollisionException</code>s, and handle those differently from other database exceptions.</p> <p>What I found easiest for doing this was an MVC design pattern where every table was represented by a PHP class (models) which I could just assign member variables to and call a <code>save</code> method to save to the database, similar to:</p> <pre><code>try { $user = new User(); $user-&gt;username = 'bob'; $user-&gt;setPassword($_POST['password'); // Could do some SHA1 functions or whatever $user-&gt;save } catch(DatabaseCollisionException $ex) { displayMessage("Sorry, that username is in use"); } catch(DatabaseException $ex) { displayMessage("Sorry, a database error occured: ".$ex-&gt;message()); } catch(Exception $ex) { displayMessage("Sorry, an error occured: ".$ex-&gt;message()); } </code></pre> <p>For more information on similar design patterns, see:</p> <ul> <li><a href="http://www.phpactiverecord.org/" rel="nofollow noreferrer">http://www.phpactiverecord.org/</a></li> <li><a href="http://book.cakephp.org/view/17/Model-Extensions-Behaviors" rel="nofollow noreferrer">http://book.cakephp.org/view/17/Model-Extensions-Behaviors</a></li> <li><a href="http://www.derivante.com/2009/05/14/php-activerecord-with-php-53/" rel="nofollow noreferrer">http://www.derivante.com/2009/05/14/php-activerecord-with-php-53/</a></li> </ul> <p>Of course this isn't the only answer, it's just some ideas you might find helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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