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
 

Casting Dates

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';
//set date_insert to 10 january 2005
$user->date_insert = DB_DataObject_Cast::date( 2005, 01, 10 );
$user->insert();
 

Casting Blobs

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';
//insert picture for this user
$user->picture = DB_DataObject_Cast::blob( file_get_contents( 'myimage.jpg' ) );
$user->insert();
 

Casting SQL

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';
//sql casting
$user->date_insert = DB_DataObject_Cast::sql( "now()" );
$user->insert();
 
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 2012
anunturi gratuite in Romania
ceasuri online de vanzare
anvelope iarna si all season
Privacy Policy | Top Searches | Cheap web hosting | Ringtomes | Shared Hosting Valid HTML 4.01 Transitional Valid CSS!