[Phpwm] [phpwm] Database extraction

Adam Smith adam.smith at mobilefun.co.uk
Fri Apr 9 15:16:07 UTC 2010


Hey Gav,

I think you mean 'database abstraction', our team has found that propel is
more than enough for our needs, you specify a schema in xml which is
relatively straight forward and you define table relations in the schema as
well. It will produce the create sql statements and then generate classes
for your tables. You can then easily extends them by modifying the class.
You then do queries by either selecting by id from the 'peer' object, for
example:

  $product = ProductPeer::retrieveByPK($id);

or you can create a criteria:

  $c = new Criteria();
  $c->add(ProductPeer::PRODUCT_STATUS, 45);
  $c->add(ProductPeer::ACTIVE, true);

  $products = ProductPeer::doSelect($c);

retrieving cell values is easy:

  $product_name = $product->getName();

modifying elements is easy enough, if a product has a name you modify it by:

  $product->setName($new_name);

and to save changes:

  $product->save();

and if you want to delete from the database:

  $product->delete();

Additionally if a category has products you can get them using:

$category->getProducts();

Although this requires you to specify a name for the relation in the schema.

Hope this is helpful.

Kind Regards,

Adam Smith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/phpwm/attachments/20100409/dbab7dbe/attachment.htm 


More information about the Phpwm mailing list