PHP Classes

DBO: Automate MySQL database access using PDO

Recommend this page to a friend!
     
  Info   Example   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: 365 All time: 6,864 This week: 455Up
Version License PHP version Categories
dbo 1.0.1GNU General Publi...4.5PHP 5, Databases
Description 

Author

This class can automate MySQL database access using PDO.

It extends the PDO class and assembles a connection string to connect to a given MySQL database server.

The class can execute prepared queries extracting the query parameter types automatically by parsing the query to get the marks for the parameters of different types.

The query parameter values are passed next to the query parameter.

Picture of John Diaz
  Performance   Level  
Name: John Diaz <contact>
Classes: 3 packages by
Country: Colombia Colombia
Age: 42
All time rank: 289815 in Colombia Colombia
Week rank: 288 Up6 in Colombia Colombia Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

/*
This is only an example script, this must be adapted to your connection params, and use an existing database with existing tables.
*/

include('DBO.php');
   
$pdoConfig = new stdClass();
   
$pdoConfig->_database = isset($dbname) ? $dbname : '';
   
$pdoConfig->_server = isset($servername) ? $servername : '';
   
$pdoConfig->_user = isset($dbusername) ? $dbusername : '';
   
$pdoConfig->_password = isset($dbpassword) ? $dbpassword : '';
   
$pdoConfig->_engine = 'mysql';
   
$pdoConfig->_showErrors = true;
   
$DBO = new DBO($pdoConfig);
   
   
//Using table prefix
   
define('TABLE_PREFIX', 'mydb_');
   
$query = $DBO->query(
       
"SELECT * FROM {my_table} WHERE id = ? ORDER BY order ASC ", 1
   
);
   
   
var_dump($query);
   
   
// With param types '%d' = int, '%s' = string, '%b' = boolean
   
$query1 = $DBO->query(
       
"SELECT * FROM my_table WHERE id = '%d' ORDER BY order ASC ", 1
   
);

   
var_dump($query1);

   
// Only the first record
   
$query2 = $DBO->queryFirst(
       
"SELECT * FROM my_table WHERE parentId = '%d' ORDER BY order ASC ", 1
   
);

   
var_dump($query2);
   


  Files folder image Files (2)  
File Role Description
Plain text file DBO.php Class Main DBO Class
Accessible without login Plain text file example.php Example Example file of using DBO class

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  
 0%
Total:365
This week:0
All time:6,864
This week:455Up