PHP Classes


Recommend this page to a friend!
  Classes of P Guardiario  >  PHP MySQL ActiveRecord class  >  >  Download  
Role: Documentation
Content type: text/plain
Description: Documentation
Class: PHP MySQL ActiveRecord class
Map objects to MySQL records using ActiveRecord
Author: By
Last change: added boolean, types
Date: 6 months ago
Size: 889 bytes


Class file image Download
A 'pretty good' activerecord style mysql abstraction lib for php.
- Php version >= 5.3.0
- Mysql (No mysqli or PDO requirement)
- Tables must bave an id primary key as int auto_increment

require 'pgtable.php';

class Product extends PGTable{
  public static $table_name = 'products';

PGTable::initialize('username', 'password', 'database', 'host');

foreach(Product::all() as $product){
  echo $product->attributes['name'] . "\n";

Magic methods: these don't need to be defined
$product = Product::find_by_foo_and_bar;
$products = Product::find_all_by_foo_and_bar;

Check for duplicate before saving
$product = Product::find_by_unique_id($unique_id);
if(!$product) $product = new Product();
$product->update_attributes(array('name' => 'foo', 'price' => '9.95'));

For more information send a message to info at phpclasses dot org.