Quick Start

Version 2 (Kien La, 2010-06-19 12:11 PM) → Version 3/4 (Kien La, 2010-06-19 01:30 PM)

h2. Quick Start

This guide will show you the bare essentials to get up and running with php-activerecord. I will assume you have downloaded the library into your include_path in a directory called php-activerecord.

The first steps are to include the library and define our database connection:

<pre class="code"><code class="php">
require_once 'php-activerecord/ActiveRecord.php';

'development' => 'mysql://username:password@localhost/database_name'));
</code></pre> </pre>

Next, lets create a model for a table called users. We'll save this class in the file models/User.php

<pre class="code"><code class="php">
class User extends ActiveRecord\Model
</code></pre> </pre>

That's it! Now you can access the users table thru the User model.

<pre class="code"><code class="php">
# create Tito
$user = User::create(array('name' => 'Tito', 'state' => 'VA'));

# read Tito
$user = User::find_by_name('Tito');

# update Tito
$user->name = 'Tito Jr';

# delete Tito
</code></pre> </pre>

Easy, huh?