SQLBuilder

Version 1 (wesen 3000, 2011-08-15 02:31 AM) → Version 2/6 (wesen 3000, 2011-08-15 02:32 AM)


h2. SQLBuilder

This guide will show you how to use the php-activerecord SQL builder.

The first steps are to get the database connection and setup the SQL builder.

<pre class="code"><code class="php">
$cfg = ActiveRecord\Config::instance();
$conn = $cfg->get_connection("development");
$builder = new ActiveRecord\SQLBuilder($conn, "authors");
</code></pre>

We are now ready to generate a simple SELECT query:

<pre class="code"><code class="php">


$builder->where("name = ?", "Hemingway");
echo $builder; /* => SELECT * FROM authors WHERE name = ? */
print_r($builder->get_where_values()); /* => array("Hemingway") */
</code></pre> </class>
</pre>