 |
|
| By |
| Last updated: September 14, 2005 |
| |
- - A simple example
- - select, insert, update, delete
- Joins - Linking related tables
|
|
| |
| Source code: |
| |
When working with a more complex database, there's a great chance that you have relations between database tables.
DB_DataObject offers a smooth way to define relations between these tables.
So first you have to create a file called 'databasename.links.ini', and then copy it to database schema location directory, defined in dbconfig.php, in our case includes/dataobject directory
In 'databasename.links.ini' we define foreign keys for each table, like in the next example.
|

|
| In the picture above you can notice relation between clients table and images table. We assume that a client can have one or more images.
Clients_id in the images table, is the foreign key. |
[images]
clients_id = clients:clients_id
|
|
And now let's make a join between these two tables, using JoinAdd method.
|
require_once( 'startup.php' );
$client = DB_DataObject::factory( 'clients' );
$images = DB_DataObject::factory( 'images' );
$client->joinAdd( $images );
|
|
A second argument can be specified for JoinAdd method, which tells what kind of join should be made: INNER(default value), LEFT, RIGHT. |
|
| |
|
 |
|