AskBee.NET
Google
AskBee - Articles, Tutorials.
   Categories    Resources
   Photo Gallery    Contact

Categories / php / DB_DataObject

By Bee
Last updated: September 14, 2005
 
  1. Configuration - A simple example
  2. Using common sql commands - select, insert, update, delete
  3. Joins - Linking related tables
  4. SQL Casting
  5. Debug queries
  6. Other usefull features
 
Source code: Using common sql commands
 
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.

DataObject Model

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.
;define foreign keys for images table
[images]
clients_id = clients:clients_id
And now let's make a join between these two tables, using JoinAdd method.

//include configuration file
require_once( 'startup.php' );

//create client object
$client = DB_DataObject::factory( 'clients' );

//create images object
$images = DB_DataObject::factory( 'images' );

//joint client and images tables
$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.
prev page Previous Page
Next Page next page
Advertising
Are you paying more than $170 per month on your credit cards?
Let us help you. Free Debt Relief !
Host your website now
Unlimited Hosting
Cheap Hosting
Bee recommends:
SEO Articles
AskBee Hosting Plans
Affordable hosting
AskBEE Directory
www.codeworkshq.com
www.averagedesign.com
www.4invent.com
Catering
Anunturi online
revelion 2009
Privacy Policy | Top Searches | Cheap web hosting | Ringtomes | Shared Hosting Valid HTML 4.01 Transitional Valid CSS!