SQLBuilder

Version 2 (wesen 3000, 2011-08-15 02:32 AM)

1 1
h2. SQLBuilder
2 1
3 1
This guide will show you how to use the php-activerecord SQL builder.
4 1
5 1
The first steps are to get the database connection and setup the SQL builder.
6 1
7 1
<pre class="code"><code class="php">
8 1
$cfg = ActiveRecord\Config::instance();                                                                                                                              
9 1
$conn = $cfg->get_connection("development");                                                                                                                         
10 1
$builder = new ActiveRecord\SQLBuilder($conn, "authors"); 
11 2 wesen 3000
</code></pre>
12 1
13 2 wesen 3000
We are now ready to generate a simple SELECT query:
14 2 wesen 3000
15 2 wesen 3000
<pre class="code"><code class="php">
16 1
$builder->where("name = ?", "Hemingway");
17 1
echo $builder; /* => SELECT * FROM authors WHERE name = ? */
18 1
print_r($builder->get_where_values()); /* => array("Hemingway") */
19 2 wesen 3000
</code></pre>