PHP Classes

Extended PHP PDO: Extend the PDO class to provide enhanced features

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 382 This week: 1All time: 6,705 This week: 111Up
Version License PHP version Categories
extended-pdo 1.0.1GNU General Publi...5.0PHP 5, Databases
Description 

Author

This class extends the PDO class to provide enhanced features. Currently it can:

- Set table name alias eventually read from CSV files
- Get primary key column name of a table
- Check if a table exists
- Execute SQL INSERT, UPDATE and DELETE queries from parameter values for tables, field name and values
- Get total number of rows of a table matching a condition
- Get SQL for LIKE condition matching a column with values from CSV string
- Get one table record
- Format MySQL date and time values
- Check if table record exists with a given field value
- Fetch individual or all result rows
- Validate MySQL date and time values

Picture of Md. Shahadat Hossain Khan Razon
  Performance   Level  
Name: Md. Shahadat Hossain ... <contact>
Classes: 14 packages by
Country: Bangladesh Bangladesh
Age: 43
All time rank: 2986 in Bangladesh Bangladesh
Week rank: 120 Up3 in Bangladesh Bangladesh Up

Example

<?php

include_once dirname(__FILE__).'/extendedpdo.cls.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);



?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Extended PDO Example</title></head>
<body><h2>Extended PDO Example</h2>
<?php


$db
=new ExtendedPDO('localhost', 'root', 'my password', 'my database name');
#$db->setDebugLevel(1);

echo '<h3>current selected database: '.$db->getCurrentDatabase().'</h3>';
$db->setCurrentTable('ri_customers');
echo
'<h3>current selected table: '.$db->getCurrentTable().'</h3>';

$data['user_id_of_outlet_owner']='razon';
$data['user_id_of_customer']='sumon';
$data['customer_name']='razon khan ['.date('r').']';
$data['customer_address']='n/a';
$data['customer_contact1']='sonadanga';
$data['customer_contact2']='khulna';

$insertedid=$db->sqlCreateUpdate($data);
if(
$insertedid){
   
$customerdata=$db->read($insertedid);
   
#$customerdata=$db->getRecordAssoc($insertedid);
   
echo '<pre>'.print_r($customerdata, true).'</pre>';
   
$customerdata=$db->getRecordAssocFromSQL('select * from `ri_customers` where `customer_id`='.$insertedid);
    echo
'<h3>data using $db->getRecordAssocFromSQL(select statement)</h3>';
    echo
'<pre>'.print_r($customerdata, true).'</pre>';

   
$rs=$db->query('select * from `ri_customers` where `customer_id`='.$insertedid.' limit 1');
    echo
'<h3>variable test: '.$rs->razon.'</h3>';
    if(
$rs && $rs->num_rows>0){
        echo
'<h4>Fetch Array</h4>';
       
$customerdata=$db->sqlFetchArray($rs);
        echo
'<pre>'.print_r($customerdata, true).'</pre>';
    }else echo
'<h3 style="color: #f00;">data not found for id - '.$insertedid.'</h3>';
   
   
$rs=$db->query('select * from `ri_customers` where `customer_id`='.$insertedid.' limit 1');
    if(
$rs && $rs->num_rows>0){
        echo
'<h4>Fetch Row</h4>';
       
$customerdata=$db->sqlFetchRow($rs);
        echo
'<pre>'.print_r($customerdata, true).'</pre>';
    }else echo
'<h3 style="color: #f00;">data not found for id - '.$insertedid.'</h3>';
   
   
$rs=$db->query('select * from `ri_customers` where `customer_id`='.$insertedid.' limit 1');
    if(
$rs && $rs->num_rows>0){
        echo
'<h4>Fetch Assoc</h4>';
       
$customerdata=$db->sqlFetchAssoc($rs);
        echo
'<pre>'.print_r($customerdata, true).'</pre>';
    }else echo
'<h3 style="color: #f00;">data not found for id - '.$insertedid.'</h3>';
   
   
$rs=$db->query('select * from `ri_customers` where `customer_id`='.$insertedid.' limit 1');
    if(
$rs && $rs->num_rows>0){
        echo
'<h4>Fetch Object</h4>';
       
$customerdata=$db->sqlFetchObject($rs);
        echo
'<pre>'.print_r($customerdata, true).'</pre>';
    }else echo
'<h3 style="color: #f00;">data not found for id - '.$insertedid.'</h3>';

}else echo
'<h2 style="color: #f00;">No data inserted due to error!</h2>';

echo
'<h3>total number of rows into '.$db->getCurrentTable().' - '.$db->getNumberOfRows().'</h3>';
echo
'<h3>total number of rows into ri_products - '.$db->getNumberOfRows(NULL, 'ri_products').'</h3>';
echo
'<h3>like operator sql test: '.ExtendedMySQLi::getSqlForLikeOperator('customer_name', 'razon,sumon, karim', 'or').'</h3>';
echo
'<h3>today is - '.ExtendedMySQLi::getMysqlFormatedDateTime().', date part of today is - '.ExtendedMySQLi::getMysqlFormatedDate().', time part of today is - '.ExtendedMySQLi::getMysqlFormatedTime().'</h3>';
echo
'<h3>is it valid date time format? '.(ExtendedMySQLi::isValidDateTime('2001-05-08 15:15:18')?'yes':'no').'</h3>';
echo
'<h3>is it valid date format? '.(ExtendedMySQLi::isValidDateTime('2001-05-08', true, false)?'yes':'no').'</h3>';
echo
'<h3>is it valid time format? '.(ExtendedMySQLi::isValidDateTime('25:15:18', false, true)?'yes':'no').'</h3>';

# encryption & decryption
function testEncryptDecrypt($piDb, $str2encrypt, $encryptsalt){
   
$encrypted=$piDb->aesEncrypt($str2encrypt, $encryptsalt);
   
$decrypted=$piDb->aesDecrypt($encrypted, $encryptsalt);
    echo
'<h3>Data to encrypt: '.$str2encrypt.', Salt for encryption: '.(isset($encryptsalt)?$encryptsalt:'NULL').', Encrypted: '.$encrypted.', Decrypted: '.$decrypted.', Encryption Status: '.($decrypted==$str2encrypt?'OK':'Not OK').'</h3>';
}
testEncryptDecrypt($db, '654321', 'razon');
testEncryptDecrypt($db, '6543210', 'razon');
testEncryptDecrypt($db, '654321', 'razon'.time());
testEncryptDecrypt($db, 'sumOn321', 'my secret key');

# reading from database
echo '<h3>Available Customers using $db->getAllRows(...)</h3><pre>'.print_r($db->getAllRows('select customer_id, user_id_of_outlet_owner, customer_name from ri_customers'), true).'</pre>';
echo
'<h3>Available Customers using $db->getRows(..., ...)</h3><pre>'.print_r($db->getRows('customer_id', 'select customer_id, user_id_of_outlet_owner, customer_name from ri_customers'), true).'</pre>';
echo
'<h3>Available Customers using $db->getArrWithIdAsKey(...)</h3><pre>'.print_r($db->getArrWithIdAsKey('select customer_id, customer_name from ri_customers'), true).'</pre>';

?>
</body>
</html>


  Files folder image Files  
File Role Description
Plain text file extendedpdo.cls.php Class ExtendedPDO Class File
Accessible without login Plain text file eg.php Example Example

 Version Control Unique User Downloads Download Rankings  
 0%
Total:382
This week:1
All time:6,705
This week:111Up