PDO Wrapper Class in PHP

PDO Wrapper Class in PHP

A Simple and use full PDO wrapper

Every good programming language and development tool has a vast and flexible developing environment. Same is with PDO. PDO is an extension of PHP and we know about it but today we will discuss a PDO wrapper class in PHP. We will discuss about the reasons for having the wrapper class and then some of its examples.

Wrapper Class Benefits:

PDO and mysqli prepared statements were designed for the multiple execution. But prepare and bind are being called only once, and after that execute is called multiple times with different data sets. That is the reason we need this code. However, it is also reality that multiple execution is used also rarely, and prepared statements are being  used mostly to execute the query for only once. In a nutshell, it is necessary  to write the same repetitive code for the every single query again and again.

Switching from old mysql functions to either PDO or mysqli is not an easy game. The one reason it that new extensions of mysqli/PDO don’t save the connection internally, – so, we have to handle it ourselves.


To overcome this issue we will use a  singleton pattern. I know that it is greatly despised but developers have to know that there are many styles of PHP code. And if you are using just mysql_query() mixed with HTML , the singleton can’t harm it. Of course, it will remove the pains of transition.

So, we have a very simple and use full PDO wrapper. We will look in detail here.

PDO Wrapper Class in PHP

Connecting with database

Database table creation

Insert records in DB

Update records in DB

Read/Fetch records from DB

Delete records in DB

Users are interested in these Articles

How to use PDO database connection in PHP

PHP PDO CRUD Using MySQL Bootstrap Tutorial

Ajax Login form using PHP MySQL and PDO

Ajax Signup form using php , MySQL and PDO