Casting - Dates, Blobs and Null

Casting - Dates, Blobs and Null --  DB_DataObject_Cast ::date(), ::blob(), ::sql()

Dealing with Casting, (everything except strings and numbers)

Warning

This is experimental!, although it is documented, it currently only supports a limited amount of databases (send me fixes if you want it to support your favorite database), and the internal operations/API may change in the future..

DataObjects is a very easy way to work with databases that are focused on numbers and strings. You can also use it on date fields (although you must format your strings correctly), and you can use it with other types by using raw SQL query(), and the string value "null" is automatically converted to NULL in the database.

In an effort to provide a cleaner way to code to the richer database types, the DB_DataObject_Cast object was created. It's purpose is to simply create an object to represent some of the more unusual types. Below is an example of using it to create a few simple types.

Cast Objects can be used in both building queries, and assigning values

As you can see, This component is in it"s infancy, so if you have any feature requests, ideas, please do not hesitate to contact me at alan_k at php dot net.

The blob and string type

Blobs are fields which can store large amounts of binary data in the databases.

At present only blobs is only supported in postgres using the bytea type. (please email me with code for other databases.)

The date type

Most dates are stored in a database in ISO standard format, this method, allows you to create date types, from either Year,month,day, Human readable day/month/year, or standard iso format year-month-day. It fills in the remaining values based on simple rules.

The sql type

Some types are sql specific, or may even be database specific, you can use the sql type to put raw strings as part of the sql statement.