Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How well did you look into Doctrine? I am using Doctrine 1.2 for these kind of things. Quite easy to setup, allows you to start off with an existing schema. It automatically figures out the relations between tables that have foreign key constraints.</p> <p>It has extensive trigger and behaviour support, so the bonus points can be spent as well, and it has relational support as well, so your additional queries are not necessary. It has beautiful lazy loading, and it comes with a flexible query language (called DQL) that allows you to do almost exactly the same stuff that you can do in SQL in only a fraction of the effort.</p> <p>Your example will look like this:</p> <pre><code>/* To just find one user */ $user = Doctrine::getTable('User')-&gt;findOneById($id); /* Alternative - illustrating DQL */ $user = Doctrine_Query::create() -&gt;from('User u') -&gt;where('u.id = ?',array($id)) -&gt;fetchOne(); $user-&gt;name = 'John Woo'; $user-&gt;save(); </code></pre> <blockquote> <p>It must be able to work alongside the existing raw mysql_* queries. I have no idea how hydrating ORMs like Doctrine 2 or Propel behave when scripts are manually manipulating the data in the database behind their backs, but I assume it's not pretty.</p> </blockquote> <p>Well, that is technically impossible to auto-manage; a SQL database is simply not pushing back stuff to your ORM, so to update stuff that was changed in the background, you need to perform an additional query one way or the other. Fortunately, Doctrine makes this very easy for you:</p> <pre><code>/* @var User $user */ /* Change a user using some raw mysql queries in my spaghetti function */ $this-&gt;feedSpaghetti($user-&gt;id); /* Reload changes from database */ $user-&gt;refresh(); </code></pre>
    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.
 

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