PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of John Diaz   DBO   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file of using DBO class
Class: DBO
Automate MySQL database access using PDO
Author: By
Last change:
Date: 9 years ago
Size: 1,204 bytes
 

Contents

Class file image Download
<?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);