PHPackages                             hackerpro536/pdo-class-wrapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. hackerpro536/pdo-class-wrapper

ActiveLibrary[Database &amp; ORM](/categories/database)

hackerpro536/pdo-class-wrapper
==============================

PDO Class Wrapper is a wrapper class of PDO (PHP Data Object) library. As we know that in any web application, database makes an important role for developer to create a good dynamic web application.

1.0.3(4mo ago)1222LGPL-3.0PHPPHP &gt;=5.0.0

Since Jan 26Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/hackerpro536/PDO_Class_Wrapper)[ Packagist](https://packagist.org/packages/hackerpro536/pdo-class-wrapper)[ Docs](https://github.com/hackerpro536/PDO_Class_Wrapper)[ RSS](/packages/hackerpro536-pdo-class-wrapper/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (4)Used By (0)

#### PHP PDO Class Wrapper

[](#php-pdo-class-wrapper)

##### \[A Wrapper Class of PDO\]

[](#a-wrapper-class-of-pdo)

\*Version 1.3 \* ###### New update for PHP8

[](#new-update-for-php8)

##### Project information

[](#project-information)

- Started: 20 September 2017. - Project Manager: \[HackerPro536 (LE VAN PHU)\]() . - Copyrights: 2017 LP Group. - Version: 1.3 - PHP 8.x Our Service - Dịch vụ của chúng tôi
-----------------------------------

[](#our-service---dịch-vụ-của-chúng-tôi)

- [Dịch vụ thiết kế website](https://lptech.asia/dich-vu/thiet-ke-website)
- [Dịch vụ SEO](https://lptech.asia/dich-vu/dich-vu-seo)
- [Dịch vụ Kols](https://lptech.asia/dich-vu/dich-vu-booking-kol-influencer-uy-tin-tang-nhan-dien-thuong-hieu)
- [Dịch vụ Pr Booking](https://lptech.asia/dich-vu/dich-vu-booking-pr-bao-chi-uy-tin-cho-doanh-nghiep)
- [Dịch vụ Content](https://lptech.asia/dich-vu/dich-vu-content)
- [Dịch vụ Marketing tổng thể](https://lptech.asia/dich-vu/giai-phap-marketing-tong-the-cho-doanh-nghiep-vua-va-nho)

##### Installation

[](#installation)

\### System requirements - PHP version: 7.0 and lasted. - MySQL version: Recommend 5.6 and above. Please keep in mind that this project is licensed by [LP Group](http://levanphu.info):

1. Only authenticated developers can download from the link above.
2. Published website must be PMS authorised clients.

Any other cases of uses not mentioned above is prohibited. If you have illegal copy of this project, please kindly to contact us for our further supporting.

LP Group
========

[](#lp-group)

1. HackerPro536 (LE VAN PHU) - CEO.

##### Introduction:

[](#introduction)

PDO Class Wrapper is a wrapper class of PDO (PHP Data Object) library. As we know that in any web application, database makes an important role for developer to create a good dynamic web application. We can use different database drivers to make web more and more interactive and dynamic. But in any web project we also know that Security is a big part and concern for developers. Every developer wants to keep user's data very safe. Hence, we use much built-in functionality in PHP to prevent unauthorized access for database e.g. mysql\_real\_escape\_string (), addslashes () etc. But some time it's very difficult to manage big application with big chunk of code. So PHP improves MySQL to MySQLi (MySQL Improved). According to php.net The MySQLi extension has a number of benefits, the key enhancements over the MySQL extension being:Object-oriented interface

1. Support for Prepared Statements
2. Support for Multiple Statements
3. Support for Transactions
4. Enhanced debugging capabilities
5. Embedded server support

##### What is the PDO MYSQL driver?

[](#what-is-the-pdo-mysql-driver)

The PDO MYSQL driver is not an API as such, at least from the PHP programmer's perspective. In fact the PDO MYSQL driver sits in the layer below PDO itself and provides MySQL-specific functionality. The programmer still calls the PDO API, but PDO uses the PDO MYSQL driver to carry out communication with the MySQL server. The PDO MYSQL driver is one of several available PDO drivers. Other PDO drivers available include those for the Firebird and PostgreSQL database servers. The PDO MYSQL driver is implemented using the PHP extension framework. Its source code is located in the directory ext/pdo\_mysql. It does not expose an API to the PHP programmer.

##### Comparison of MySQL API options for PHP

[](#comparison-of-mysql-api-options-for-php)

[![PDO Comparison](https://camo.githubusercontent.com/aa3228ca90afe3f21f084811ff61302913638ad118b6d2a0057bd80a6226017a/68747470733a2f2f7261772e6769746875622e636f6d2f6e656572616a73696e6768736f6e752f50444f5f436c6173735f577261707065722f6d61737465722f636f6d70617269736f6e2e6a7067 "PDO Comparison")](https://camo.githubusercontent.com/aa3228ca90afe3f21f084811ff61302913638ad118b6d2a0057bd80a6226017a/68747470733a2f2f7261772e6769746875622e636f6d2f6e656572616a73696e6768736f6e752f50444f5f436c6173735f577261707065722f6d61737465722f636f6d70617269736f6e2e6a7067)

##### About PDO Class Wrapper:

[](#about-pdo-class-wrapper)

PDO Class Wrapper is a wrapper class of PDO (PHP Data Object) library. It has many useful built in functions to manage your web application database code very shorter. Also you will find some helpful method to fix your bug with very ease.

\[source: Net Tut+\]

##### Advantage of using PDO:

[](#advantage-of-using-pdo)

Many PHP programmers learned how to access databases by using either the MySQL or MySQLi extensions. As of PHP 5.1, there is a better way. PHP Data Objects (PDO) provides methods for prepared statements and working with objects that will make you far more productive!

##### PDO Class Wrapper Features:

[](#pdo-class-wrapper-features)

PDO Class Wrapper has very classic methods like any database class library:

```

MySQL query									pdoQuery()
MySQL select query							select ()
MySQL insert query 							insert ()
MySQL insert batch							insertBatch()
MySQL update query							update()
MySQL delete query 							delete()
MySQL truncate table						truncate()
MySQL drop table							drop()
MySQL describe table						describe()
MySQL count records							count()
Show/debug executed query					showQuery()
Get last insert id							getLastInsertId()
Get all last insert id						getAllLastInsertId()
Get MySQL results							results()
Get MySQL result							result()
Get status of executed query				affectedRows()
MySQL begin transactions					start()
MySQL commit the transaction				end()
MySQL rollback the transaction				back()
Debugger PDO Error 							setErrorLog()

```

##### How to Connect PDO Class:

[](#how-to-connect-pdo-class)

###### Example: \[A\]

[](#example-a)

```
$dbConfig = array
(
"host"=>"localhost", "dbname"=>'mydb', "username"=>'root', "password"=>''
);
$db = new PdoWrapper($dbConfig);
```

###### Example: \[B\]

[](#example-b)

```
$dbConfig = array
(
"host"=>"localhost", "dbname"=>"mydb", "username"=>'root', "password"=>''
);
$db = PdoWrapper::getPDO($dbConfig);
```

#### PDO Class Wrapper Methods **Explanations:**

[](#pdo-class-wrapper-methods-explanations)

##### pdoQuery():

[](#pdoquery)

Method name and parameter

```
pdoQuery ( string $sSql, array $aBindWhereParam)
```

**Explanations:**This method is use for simple MySQL query; you can execute your MySQL query with parameterized parameter or as simple query.

**Example:**

```
$sql = 'select * from customers limit 5;';
$data = $pdo->pdoQuery($sql)->results();

Raw Query:
SELECT * FROM customers LIMIT 5;

$sql = "select * from customers where (customernumber = '0000' OR customernumber = '45121') ;";
$data = $pdo->pdoQuery($sql)->results();

Raw Query:
SELECT * FROM customers WHERE (customernumber = 103 OR customernumber = 119) ;

$sql = "select * from customers where (customernumber = '0000' OR customernumber = '45121') ;";
$data = $db->pdoQuery($sql)->results();

Raw Query:
SELECT * FROM customers WHERE (customernumber = '0000' OR customernumber = '45121') ;

$sql = "select p.checknumber, p.amount, p.paymentdate, c.customernumber,
c.customerName, c.contactLastName, c.contactFirstName, c.phone, c.addressLine1,
c.addressLine2, c.city, c.state, c.postalCode, c.country from payments as p
inner join customers as c on p.customernumber = c.customernumber
order by p.amount desc limit 2;";
$data = $pdo->pdoQuery($sql)->results();

Raw Query:
SELECT p.checknumber, p.amount, p.paymentdate, c.customernumber, c.customername,
c.contactlastname, c.contactfirstname, c.phone, c.addressline1, c.addressline2,
c.city, c.state, c.postalcode, c.country FROM payments AS p INNER JOIN
customers AS c ON p.customernumber = c.customernumber ORDER BY p.amount DESC LIMIT 2;
```

#### select():

[](#select)

Method name and parameter

```
select (string $sTable , array $aColumn, array $aWhere, string $sOther)
```

**Explanations:**The select method is made for get table data from just pass table name in method, if you omit column then you will get all fields of requested table else you can pass table field by an array. If you want to pass a where clause then you can use third parameter of select method and by pass fourth parameter you can send other filters.

**Example:**

```
Get all table fields from table without passing 2nd parameter.

$select = $pdo->select('customers');
$data = $select->results();

Raw Query:
SELECT * FROM `customers` ;

Or

You can use one line code to get a result array

$data = $pdo->select('employees')->results();

Raw Query:
SELECT * FROM `employees` ;

Get only selected fields from table

$data = $db->select('employees', array('employeeNumber','lastName','firstName'))->results();

Raw Query:
SELECT employeenumber, lastname, firstname FROM `employees` ;

Or

$fieldsArray = array('employeeNumber','lastName','firstName');
$data = $db->select('employees', $fieldsArray)->results();

Raw Query:
SELECT employeenumber, lastname, firstname FROM `employees` ;

$selectFields = array('employeeNumber','lastName','firstName');
$whereConditions = array('lastname'=>'bow');
$data = $db->select('employees', $selectFields, $whereConditions, 'ORDER BY employeeNumber DESC LIMIT 5')->results();

Raw Query:
SELECT employeenumber, lastname, firstname FROM `employees` WHERE lastname = "bow" ORDER BY employeenumber DESC LIMIT 5;

Custom Where Clause with Select Method:

You can set your own custom where clause

$whereConditions = array('lastname ='=>'bow', 'or jobtitle ='=> 'Sales Rep', 'and isactive ='=>1, 'and officecode ='=> 1 );
$data = $db->select('employees','',$whereConditions)->results();

Raw Query:
SELECT * FROM `employees` WHERE lastname = "bow" OR jobtitle = "sales rep" AND isactive = 1 AND officecode = 1 ;

OR

$whereConditions = array('lastname ='=>'bow', 'or jobtitle ='=> 'Sales Rep', 'and isactive ='=>1, 'and officecode ='=> 1 );
$data = $db->select('employees',array('employeenumber','lastname','jobtitle'),$whereConditions)->results();

Raw Query:
SELECT employeenumber, lastname, jobtitle FROM 'employees' WHERE lastname = "bow" OR jobtitle = "sales rep" AND isactive = 1 AND officecode = 1 ;
```

#### insert():

[](#insert)

Method name and parameter

```
insert( string $sTable, array $aData )
```

**Explanations:**By insert method you can insert record into selected table. Just pass data as an array with fields as array key and the array data will insert in to table. Insert method automatically convert your array data in to SQL injection safe data.

**Example:**

```
$dataArray = array('first_name'=>'Sid','last_name'=>'Mike','age'=>45);
$data = $db->insert('test',$dataArray)->getLastInsertId();

Raw Query:
INSERT INTO `test` (first_name,last_name,age) VALUES ("sid","mike",45);
```

#### insertBatch():

[](#insertbatch)

Method name and parameter

```
insertBatch(string $sTable, array $aData, boolean $safeModeInsert )
```

**Explanations:**You can use this method for inserting multiple array data in same table. You have to just send full array data and rest of thing insertBatch will handle. You can send third parameter as false if you don't want to insert parameterize insert or send true if want to secure insertions. insertBatch works with MySQL transactions so you don't need to worry about failure data. It will be rollback if anything goes wrong.

**Example:**

```
$dataArray[] = array('first_name'=>'Sid','last_name'=>'Mike','age'=>45);
$dataArray[] = array('first_name'=>'Scott','last_name'=>'Dimon','age'=>78);
$dataArray[] = array('first_name'=>'Meena','last_name'=>'Verma','age'=>23);
$data = $db->insertBatch('test',$dataArray, true)->getAllLastInsertId();

Raw Query:
INSERT INTO `test` (first_name, last_name, age) VALUES ("sid", "mike", 45);
INSERT INTO `test` (first_name, last_name, age) VALUES ("scott", "dimon", 78);
INSERT INTO `test` (first_name, last_name, age) VALUES ("meena", "verma", 23);
```

#### update():

[](#update)

Method name and parameter

```
update( string $sTable, array $aData, array $aWhere, string  $sOther)
```

**Explanations:**Update method is use for update a table with array data. You can send array data as update data in table.

**Example:**

```
$dataArray = array('first_name'=>'Sangeeta','last_name'=>'Mishra','age'=>35);
$aWhere = array('id'=>23);
$data = $db->update('test', $dataArray, $aWhere)->affectedRows();

Raw Query:
UPDATE `test` SET first_name = "sangeeta", last_name = "mishra", age = 35 WHERE id = 23 ;

Or

$dataArray = array('first_name'=>'Sonia','last_name'=>'Shukla','age'=>23);
$aWhere = array('age'=>35, 'last_name'=>'Mishra');
$data = $db->update('test', $dataArray, $aWhere)->affectedRows();

Raw Query:
UPDATE `test` SET first_name = "sonia", last_name = "shukla", age = 23 WHERE
age = 35 AND last_name = "mishra" ;
```

#### delete():

[](#delete)

Method name and parameter

```
delete( string $sTable, array $aWhere, string  $sOther )
```

**Explanations:**You can delete records from table by send table name and your where clause array.

**Example:**

```
$aWhere = array('age'=>35);
$data = $db->delete('test', $aWhere)->affectedRows();

Raw Query:
DELETE FROM `test` WHERE age = 35 ;

$aWhere = array('age'=>45, 'first_name'=> 'Sonu');
$data = $db->delete('test', $aWhere)->affectedRows();

Raw Query:
DELETE FROM `test` WHERE age = 45 AND first_name = "sonu" ;
```

#### truncate():

[](#truncate)

Method name and parameter

```
truncate( string $sTable )
```

**Explanations:**You can truncate table by just pass table name.

**Example:**

```
$data = $db->truncate('test');

Raw Query:
TRUNCATE TABLE `test`;
```

#### drop():

[](#drop)

Method name and parameter

```
drop( string $sTable )
```

**Explanations:**You can drop table by just pass table name.

**Example:**

```
$data = $db->drop('test');

Raw Query:
DROP TABLE `test`;
```

#### describe():

[](#describe)

Method name and parameter

```
describe( string $sTable )
```

**Explanations:**You can get a table field name and data type.

**Example:**

```
$data = $db->describe('test');

Raw Query:
DESC  `test`;
```

#### count():

[](#count)

Method name and parameter

```
count( string $sTable, string $sWhere )
```

**Explanations:**This function will return the number of total rows in a table.

**Example:**

```
echo $q = $p->count('employees');
$p->showQuery();

Raw Query:
23
SELECT COUNT(*) AS numrows FROM `employees`;

echo $q = $p->count('employees','firstname = "mary"');
$p->showQuery();

Raw Query:
1
SELECT COUNT(*) AS numrows FROM `employees` WHERE firstname = "mary";
echo $q = $p->count('employees','jobtitle="Sales Rep"');
$p->showQuery();

Raw Query:
17
SELECT COUNT(*) AS numrows FROM `employees` WHERE jobtitle="sales rep";
```

#### showQuery():

[](#showquery)

Method name and parameter

```
showQuery( Boolean $logfile )
```

**Explanations:**By this function you can get executed query. It will show raw query on your screen. If you want to logfile to save query then you can send 2nd param as true. By default it's false.

**Example:**

```
$db->showQuery();

Raw Query:
SELECT COUNT(*) AS numrows FROM `test`;
```

#### getLastInsertId():

[](#getlastinsertid)

Method name and parameter

```
getLastInsertId()
```

**Explanations:**Get a newly inserted id by insert function.

**Example:**

```
$lid = $db->getLastInsertId();
```

Return: Number/Integer

#### getAllLastInsertId():

[](#getalllastinsertid)

Method name and parameter

```
getAllLastInsertId ()
```

**Explanations:**Get all newly inserted id by insertBatch function.

**Example:**

```
$lid = $db->getAllLastInsertId();
```

Return: Array

#### results():

[](#results)

Method name and parameter

```
results (string $type )
```

**Explanations:**Get array result data by executed SELECT or Select Query. You can get result in three formats Array, XML and JSON. Just pass 1st param as 'array' or 'xml' or 'json'. By default it will return array.

**Example:**

```
$data = $db->results();
$data = $db->results('xml');
$data = $db->results('json');
```

Return: Array | XML | JSON

#### result():

[](#result)

Method name and parameter

```
results (integer $iRow)
```

**Explanations:**Get result from an array data by request index or false.

**Example:**

```
$data = $db->result(1);
```

Return: Array | false

#### affectedRows():

[](#affectedrows)

Method name and parameter

```
affectedRows()
```

**Explanations:**Get number of affected rows by update, delete and select etc. statement or false.

**Example:**

```
$data = $db->affectedRows();
```

Return: integer | false

#### start():

[](#start)

Method name and parameter

```
start()
```

**Explanations:**Start the MySQL transaction.

**Example:**

```
$db->start();
```

#### end():

[](#end)

Method name and parameter

```
end()
```

**Explanations:**Commit the MySQL transaction.

**Example:**

```
$db->end();
```

#### back():

[](#back)

Method name and parameter

```
back()
```

**Explanations:**Rollback the MySQL transaction.

**Example:**

```
$db->back();
```

#### setErrorLog():

[](#seterrorlog)

Method name and parameter

```
setErrorLog (boolean $mode)
```

**Explanations:**setErrorLog, method works for show/hide PDO error. If you send true then all errors will show on screen or if you send false then all errors will store in log file in same location.

**Example:**

```
$db->setErrorLog(true);
```

#### Example Connection Page:

[](#example-connection-page)

```
// include PDO Class Wrapper
include_once 'class/class.pdowrapper.php';

// set connection data
$dbConfig = array
(
"host"=>"localhost", "dbname"=>'sampledb', "username"=>'root', "password"=>''
);

// get instance of PDO Class Wrapper
$db = PdoWrapper::getPDO($dbConfig);

// set error log mode true to show all error on screen
$db->setErrorLog(true);

/* simple update example */
// update array data
$dataArray = array('first_name'=>'Sangeeta','last_name'=>'Mishra','age'=>35);

// where condition array
$aWhere = array('id'=>23);

// call update function
$q = $p->update('test', $dataArray, $aWhere)->showQuery()->affectedRows();

Output:
UPDATE `test` SET first_name = "sangeeta", last_name = "mishra", age = 35 WHERE id = 23 ;
1
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance74

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fca9b03ccc714d4aa769bd0162a01c170434c4a30e37d22ac6af8598ea96bb57?d=identicon)[hackerpro536](/maintainers/hackerpro536)

---

Top Contributors

[![hackerpro536](https://avatars.githubusercontent.com/u/22806190?v=4)](https://github.com/hackerpro536 "hackerpro536 (12 commits)")

---

Tags

databasemysqlpdodbmysql classpdohelperpdo-class-wrapper

### Embed Badge

![Health badge](/badges/hackerpro536-pdo-class-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/hackerpro536-pdo-class-wrapper/health.svg)](https://phpackages.com/packages/hackerpro536-pdo-class-wrapper)
```

###  Alternatives

[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4563.1M37](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

923530.0k13](/packages/envms-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

920249.3k8](/packages/fpdo-fluentpdo)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41240.2k4](/packages/aura-sqlschema)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
