 |
|
| By |
| Last updated: September 14, 2005 |
| |
- - A simple example
- - select, insert, update, delete
- - Linking related tables
- SQL Casting
|
|
| |
| Source code: |
| |
|
|
Let's say we have a field in our database, 'date_insert', that we want to set each time a user is insert.
We can do this thing easly by using DB_DataObject_Cast::date() method.
|
$user = DB_DataObject::factory( 'users' );
$user->name = 'Test User';
$user->date_insert = DB_DataObject_Cast::date( 2005, 01, 10 );
$user->insert();
|
|
|
| |
|
|
DB_DataObject_Cast::blob() method should be used if we want to store images into database, or large amount of binary data.
|
$user = DB_DataObject::factory( 'users' );
$user->name = 'Test User';
$user->picture = DB_DataObject_Cast::blob( file_get_contents( 'myimage.jpg' ) );
$user->insert();
|
|
|
| |
|
|
And finally, how do you set a field using a raw sql query? DB_DataObject_Cast::sql() method is the solution.
|
$user = DB_DataObject::factory( 'users' );
$user->name = 'Test User';
$user->date_insert = DB_DataObject_Cast::sql( "now()" );
$user->insert();
|
|
|
| |
| |
|
 |
|