PHP-WAX Models
The file WXActiveRecord.php is the framework's ORM (Object Relational Mapper). This class sits on top of PDO to provide object-oriented, database-agnostic, database access.
Your first job is to create a class for each of your database tables. Since most work is handled by the main WXActiveRecord class, you may not have to do anything more than the following...
class User extends WXActiveRecord {
}
All your models (as these files will be referred to) should be located at /app/model. Once you have created this class you can now interact with the model from your controller.
Use either:
$user=new User();
or
$user=new User(1);
The second method returns the row specified.
The find_all() and find() methods can also take additional parameters as an array. The full list is below.....
$params=array(
"distinct"=>"field1, field2",
"columns"=>"column1,column2",
"conditions"=>"username={$username}",
"order"=>"username",
"direction"=>"DESC",
"offset"=>"5",
"limit"=>"10"
)
$result=$user->find_all($params);
All the parameters are optional. The code above equates to the sql command...
SELECT DISTINCT field1,field2 FROM USER WHERE username=$username ORDER BY username DESC LIMIT 5,10
With the find_all method you can even perform inner joins by providing an additional array.
$join=array("table"=>"group", "lhs"=>"user_id", "rhs"=>"id");
$result=$user->find_all($params, $join);
The three parts are table, left-hand-side and right-hand-side. In a query this would appear as..
INNER JOIN table ON table.lhs=rhs
To return the number of rows in a table use the following syntax.
$rows=$user->count();
You can also feed it some conditions.....
$rows=$user->count( array('conditions'=>'status=1') );
RECENT ARTICLES
Rails and Apache
In what appears to be a very useful find ' read more
Useful bit of Javascript
Never thought about using javascript for this before but I had a requ... read more
Quick jquery Gallery
I had a look at some of the gallery plugins available for jquery and ... read more
Massive CPU usage when updating Fedora using YUM/RPMQ
We noticed that YUM and RPMQ processes were using a massive amount CP... read more