Example #1
0
<?php

// include pdo helper class to use common methods
include_once '../class/class.pdohelper.php';
// include pdo class wrapper
include_once '../class/class.pdowrapper.php';
// database connection setings
$dbConfig = array("host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '');
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);
// get instance of PDO Helper object
$helper = new PDOHelper();
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);
// select query with limit
$q = $db->pdoQuery('select * from customers;')->results();
// print array result
$helper->PA($q);
// select query with limit
$q = $db->pdoQuery('select * from customers;')->results('xml');
// print xml result
echo $q;
// select query with limit
$q = $db->pdoQuery('select * from customers;')->results('json');
// print json result
echo $q;
Example #2
0
<?php

/**
 * Function to print array with pre tag
 *
 * @param array $array
 */
function PA($array)
{
    echo '<pre>', print_r($array, true), '</pre>';
}
// include pdo class wrapper
include_once 'class.pdowrapper.php';
// create new object of class wrapper
$p = new PdoWrapper();
// select query with limit
$q = $p->pdoQuery('select * from customers;')->results();
// print array result
// PA($q); die;
// select query with limit
$q = $p->pdoQuery('select * from customers;')->results('xml');
// print xml result
// echo $q; die;
// select query with limit
$q = $p->pdoQuery('select * from customers;')->results('json');
// print json result
// echo $q; die;
Example #3
0
<?php

/**
 * Function to print array with pre tag
 *
 * @param array $array
 */
function PA($array)
{
    echo '<pre>', print_r($array, true), '</pre>';
}
// include pdo class wrapper
include_once 'class.pdowrapper.php';
// create new object of class wrapper
$p = new PdoWrapper();
// simple delete #1
// where condition array
$aWhere = array('age' => 35);
// call update function
$q = $p->delete('test', $aWhere)->traceEnable()->affectedRows();
// print affected rows
PA($q);
// simple delete #2
// where condition array
$aWhere = array('age' => 45, 'first_name' => 'Sonu');
// call update function
$q = $p->delete('test', $aWhere)->traceEnable()->affectedRows();
// print affected rows
PA($q);
Example #4
0
<?php

// include pdo helper class to use common methods
include_once '../class/class.pdohelper.php';
// include pdo class wrapper
include_once '../class/class.pdowrapper.php';
// database connection setings
$dbConfig = array("host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '');
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);
// get instance of PDO Helper object
$helper = new PDOHelper();
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);
/**
 *  run simple mysql query
 *
 *  showQuery = display executed query
 *  results = get array results
 */
$q = $db->pdoQuery('select * from customers limit 5;')->showQuery()->results();
// print array result
$helper->PA($q);
/**
 *  run simple mysql query with where clause
 *  pass where value as an parametrised array
 *
 *  ? presenting place holder here for where clause values
 */
$q = $db->pdoQuery('select * from customers where (customernumber = ? OR customernumber = ?) ;', array(103, 119))->showQuery()->results();
// print array result
Example #5
0
<?php

/**
 * Function to print array with pre tag
 *
 * @param array $array
 */
function PA($array)
{
    echo '<pre>', print_r($array, true), '</pre>';
}
// include pdo class wrapper
include_once 'class.pdowrapper.php';
// create new object of class wrapper
$p = new PdoWrapper();
// simple update #1
// update array data
$dataArray = array('first_name' => 'Sangeeta', 'last_name' => 'Mishra', 'age' => 35);
// where condition array
$aWhere = array('age' => 23);
// call update function
$q = $p->update('test', $dataArray, $aWhere)->traceEnable()->affectedRows();
// print affected rows
PA($q);
// simple update #2
// update array data
$dataArray = array('first_name' => 'Sonia', 'last_name' => 'Shukla', 'age' => 23);
// two where condition array
$aWhere = array('age' => 35, 'last_name' => 'Mishra');
// call update function
$q = $p->update('test', $dataArray, $aWhere)->traceEnable()->affectedRows();
Example #6
0
<?php

// include pdo helper class to use common methods
include_once '../class/class.pdohelper.php';
// include pdo class wrapper
include_once '../class/class.pdowrapper.php';
// database connection setings
$dbConfig = array("host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '');
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);
// get instance of PDO Helper object
$helper = new PDOHelper();
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);
// Example -1
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// set where condition
$whereConditions = array('customerNumber' => 103);
// select with where and bind param use select method
$q = $db->select('customers', $selectFields, $whereConditions)->showQuery()->results();
// print array result
PDOHelper::PA($q);
// Example -2
$whereConditions = array('lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1);
$data = $db->select('employees', array('employeenumber', 'lastname', 'jobtitle'), $whereConditions)->showQuery()->results();
// print array result
PDOHelper::PA($q);
// Example -3
$whereConditions = array('lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1);
// select with where and bind param use select method
$q = $db->select('employees', array('employeeNumber', 'lastName', 'firstName'), $whereConditions)->showQuery()->results();
Example #7
0
<?php

//300 seconds = 5 minutes execution time
ini_set('max_execution_time', 300);
// overrides the default PHP memory limit.
ini_set('memory_limit', '-1');
// include pdo helper class to use common methods
include_once '../class/class.pdohelper.php';
// include pdo class wrapper
include_once '../class/class.pdowrapper.php';
// database connection setings
$dbConfig = array("host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '');
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);
// get instance of PDO Helper object
$helper = new PDOHelper();
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);
// Example -1
$dataArray = array('first_name' => 'Sid', 'last_name' => 'Mike', 'age' => 45);
// use insert function
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
PDOHelper::PA($q);
// Example -2
$dataArray = array('first_name' => 'Scott', 'last_name' => 'Dimon', 'age' => 55);
// use insert function
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
PDOHelper::PA($q);
// Example -3
$dataArray = array('first_name' => 'Simran', 'last_name' => 'Singh', 'age' => 25);
// use insert function
Example #8
0
 /**
  * Get Instance of PDO Class as Singleton Pattern
  *
  * @param array $dsn
  *
  * @return object $oPDO
  */
 public static function getPDO($dsn = array())
 {
     // if not set self pdo object property or pdo set as null
     if (!isset(self::$oPDO) || self::$oPDO !== null) {
         // set class pdo property with new connection
         self::$oPDO = new self($dsn);
     }
     // return class property object
     return self::$oPDO;
 }
Example #9
0
//300 seconds = 5 minutes execution time
ini_set('memory_limit', '-1');
// overrides the default PHP memory limit.
/**
 * Function to print array with pre tag
 *
 * @param array $array
 */
function PA($array)
{
    echo '<pre>', print_r($array, true), '</pre>';
}
// include pdo class wrapper
include_once 'class.pdowrapper.php';
// create new object of class wrapper
$p = new PdoWrapper();
//insert example #1
$dataArray = array('first_name' => 'Sid', 'last_name' => 'Mike', 'age' => 45);
// use insert function
$q = $p->insert('test', $dataArray)->traceEnable()->getLastInsertId();
$dataArray = array('first_name' => 'Scott', 'last_name' => 'Dimon', 'age' => 55);
// use insert function
$q = $p->insert('test', $dataArray)->traceEnable()->getLastInsertId();
$dataArray = array('first_name' => 'Simran', 'last_name' => 'Singh', 'age' => 25);
// use insert function
$q = $p->insert('test', $dataArray)->traceEnable()->getLastInsertId();
// use insert function
$q = $p->insert('test', $dataArray)->traceEnable()->getLastInsertId();
// print array last insert id
PA($q);
die;
Example #10
0
<?php

/**
 * Function to print array with pre tag
 *
 * @param array $array
 */
function PA($array)
{
    echo '<pre>', print_r($array, true), '</pre>';
}
// include pdo class wrapper
include_once 'class.pdowrapper.php';
// create new object of class wrapper
$p = new PdoWrapper();
echo "// select with fields and one where condition #1";
// set fields for table
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// set where condition
$whereConditions = array('customerNumber' => 103);
// select with where and bind param use select method
$q = $p->select('customers', $selectFields, $whereConditions)->traceEnable()->results();
// print array result
PA($q);
echo "// select with fields and two where condition #2";
// set fields for table
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// set where condition
$whereConditions = array('customerNumber' => 103, 'contactLastName' => 'Schmitt');
// select with where and bind param use select method
$q = $p->select('customers', $selectFields, $whereConditions)->traceEnable()->results();
Example #11
0
<?php

// include pdo helper class to use common methods
include_once '../class/class.pdohelper.php';
// include pdo class wrapper
include_once '../class/class.pdowrapper.php';
// database connection setings
$dbConfig = array("host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '');
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);
// get instance of PDO Helper object
$helper = new PDOHelper();
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);
// Example -1
// where condition array
$aWhere = array('age' => 35);
// call update function
$q = $db->delete('test', $aWhere)->showQuery()->affectedRows();
// print affected rows
PDOHelper::PA($q);
// Example -2
// where condition array
$aWhere = array('age' => 45, 'first_name' => 'Sonu');
// call update function
$q = $db->delete('test', $aWhere)->showQuery()->affectedRows();
// print affected rows
PDOHelper::PA($q);
Example #12
0
<?php

/**
 * Function to print array with pre tag
 *
 * @param array $array
 */
function PA($array)
{
    echo '<pre>', print_r($array, true), '</pre>';
}
// include pdo class wrapper
include_once 'class.pdowrapper.php';
// create new object of class wrapper
$p = new PdoWrapper();
// select query #1
$q = $p->pdoQuery('select * from customers limit 5;')->traceEnable()->results();
PA($q);
// select query with where condition and bind param #2
$q = $p->pdoQuery('select * from customers where customernumber = ?;', array(103))->traceEnable()->results();
// print array result
PA($q);
// select query and get 2nd row of result array #3
$q = $p->pdoQuery('select * from customers;')->traceEnable()->result(2);
// print array result
PA($q);
// select query with multiple condition and bind param #4
$q = $p->pdoQuery('select * from customers where (customernumber = ? or contactLastName = ?) ;', array(112, 'Schmitt'))->traceEnable()->results();
// print array result
PA($q);
Example #13
0
<?php

require_once 'database/SQLConstants.php';
// include pdo helper class to use common methods
require_once 'PDO_Class_Wrapper/class/class.pdohelper.php';
// include pdo class wrapper
require_once 'PDO_Class_Wrapper/class/class.pdowrapper.php';
if (!isset($_SESSION)) {
    session_start();
}
?>

<?php 
// database connection setings
$dbConfig = array("host" => $host, "dbname" => $db, "username" => $username, "password" => $password, "charset" => $charset);
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);
// get instance of PDO Helper object
$helper = new PDOHelper();
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(false);
Example #14
0
 public function databaseTest()
 {
     $db = new PdoWrapper();
     $result = $db->select("test")->results();
     pad($result);
 }
 /**
  * Unset The Class Object
  */
 public function __destruct()
 {
     self::$oPDO = null;
 }