示例#1
0
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
$helper->PA($q);
/**
 *  run simple mysql query and get third row of array results
 *
 *  result(2) = will return 3rd row of array data
示例#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;
示例#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();
// 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);