O2DB is an Open Source PHP Database Library (PDO Class Wrapper). O2DB a PDO Class wrapper that equipped with SQL Query Builder is quite powerful. O2DB also the future will be equipped with SQL Forge, Schema Builder and Utilities to be quite powerful as well. Another amazing product from , released under MIT License. O2DB is build for working more powerfull with O2System Framework, but also can be used for integrated with others as standalone version with limited features.
The best way to install O2DB is to use Composer
composer require o2system/o2db
// Initialize DB
$DB = new DB(array(
'driver' => 'mysql',
'dsn' => '',
'hostname' => 'localhost',
'port' => 3306,
'username' => 'root',
'password' => 'mysql',
'database' => 'database_name',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
'prefix' => '',
'strict_on' => FALSE,
'encrypt' => FALSE,
'compress' => FALSE,
'buffered' => FALSE,
'persistent' => TRUE,
'transaction_enabled' => TRUE,
'debug_enabled' => TRUE,
'options' => array(
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => FALSE,
PDO::ATTR_EMULATE_PREPARES => FALSE
)
)
));
// Using DSN for MySQL
$DB = new DB('mysql://username:[email protected]/database_name');
// Using DSN for SQLite
$DB = new DB('sqlite://username:password/c:\xampp\htdocs\o2db\database\data.db');
// Create a query
$result = $DB->get_where('table_name', ['record_status' => 1]);
if($result->num_rows() > 0)
{
foreach($result as $row)
{
// you can call the row column like an array or an object
echo $row->column_name;
echo $row['column_name'];
}
}
// Chaining Query Building
$query = $DB->select('
tablename.name AS people_name
')->from('tablename')->where('record_status', 1)->order_by('record_ordering', 'ASC')->limit(10)->get();
If you familiar with CodeIgniter Active Record, O2DB has almost the same syntax. More details at the Wiki. (Coming Soon)
Please kindly mail us at [email protected] or [email protected].
Please kindly submit your issues at Github so we can track all the issues along development.
- PHP 5.4+
- Composer
- PDO
- Founder and Lead Projects: Steeven Andrian Salim (steevenz.com)