Cool Penguin

PersistClass for PHP - keeping SQL simple

Latest news

More

on CoolPenguin.net:

PersistClass for PHP

PersistClass is a library of PHP classes providing access to relational databases. Attempts to focus on simplicity and convenience by eliminating the need of boiler-plate, unmeaningful code.


Main features


How does it work?

It exposes a simplified, common interface for database operations. Object persistence and ORM uses this layer and generates the SQL commands, making writing of SQL commands unnecessary.

A few sample uses

Acquire a connection object

$con = DbConnectionPool::instance()->getConnection();

Execute an SQL query

$sql = 'INSERT INTO TESTTABLE(testcolumn) VALUES("INSERTSUCCESS")';
$con->query($sql);

Perform an SQL select, reading results

$sql = 'SELECT testcolumn FROM TESTTABLE';
$con->query($sql);
while($row = $con->next()) {
  $testColumn = $row['testcolumn'];
}

Mapping a PHP class to a Database table

class TestTable extends PersistClass {
  protected $sqlTableName = 'TESTTABLE';
  protected $sqlPrimaryKey = 'testid';
}

Read SQL data using mapped objects

$testRecord = new TestTable(5); // 5 is a primary key
$testColumn = $testRecord->getData('testcolumn');
$otherTestColumn = $testRecord->getData('testcolumn');

Manipulate table data through mapped objects

$testRecord->setData('testcolumn', 'new content');
$testRecord->setData('othertestcolumn', 'other new content')
$testRecord->updateDb();

Check out the examples page with detailed explanations of common use cases