PHP Classes

PHP MySQL ActiveRecord class: Map objects to MySQL records using ActiveRecord

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 529 All time: 5,661 This week: 455Up
Version License PHP version Categories
pgtable 1.0GNU General Publi...5.3.0PHP 5, Databases, Design Patterns
Description 

Author

This class can map objects to MySQL records using ActiveRecord design pattern.

It can create records in a given MySQL table using values of object variables with the same name of the table fields.

The class can also perform other operations of mapping the table records to objects like retrieving one record with a given id or some other table field, retrieve all table records, retrieve records using a given SQL query, update records with the values of the changed object variables.

Picture of P Guardiario
Name: P Guardiario <contact>
Classes: 6 packages by
Country: Philippines Philippines
Age: ???
All time rank: 162118 in Philippines Philippines
Week rank: 180 Up3 in Philippines Philippines Up

Details

PGTable A 'pretty good' activerecord style mysql abstraction lib for php. ========= Requirements: - Php version >= 5.3.0 - Mysql (No mysqli or PDO requirement) - Tables must bave an id primary key as int auto_increment ```php 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 ```php $product = Product::find_by_foo_and_bar; $products = Product::find_all_by_foo_and_bar; ``` Check for duplicate before saving ```php $product = Product::find_by_unique_id($unique_id); if(!$product) $product = new Product(); $product->update_attributes(array('name' => 'foo', 'price' => '9.95')); $product->save(); ```

  Files folder image Files (2)  
File Role Description
Plain text file pgtable.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:529
This week:0
All time:5,661
This week:455Up
User Comments (1)
msql extension is deprecated as of PHP 5.
11 years ago (Evgeniy Tkachenko)
15%Star