Database PHP

PHP Data Object (PDO) Database Connection Script

PHP Data Object (PDO) Database Connection Script
Written by Yogesh Koli

PDO Connection Script

We have new way to connect and use Database with PHP 5 or new versions.

Here I am providing a simple PHP script to connect and use Database with PDO connection.

You might think why to use PDO?

The answer is here we can use multiple databases with PDO, so like if we plan to change our database it will be quick and easy where as with MySQLi we can’t change our database we can only use and stick with MySQL.

You can install PDO from:

Let’s get started with our script:


You can always call DB() function from the script to get connection object and use throught out the script

Thinking about how to call this function and use, no worries?

Here is script to select/fetch records from database using PDO connection with PHP function:

Create Object of Demo class and call getRecords() function to display records

If you have any issue with using PDO connection script, feel free to ask questions using comment box below.

About the author

Yogesh Koli

Yogesh Koli is a software engineer & a Blogger lives in India. He's driven by an addiction to learning and a love for adventure. he has 5+ years of experience working with the front-end, back-end, web application development, and system design.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of