Home Database PHP Data Object (PDO) Database Connection Script

PHP Data Object (PDO) Database Connection Script


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: http://php.net/manual/en/pdo.installation.php

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.

Enjoy this tutorial? Get iTech Empires updates delivered straight to your inbox.

No Spam, ever. We'll never share your email address and you can opt out at any time.

Yogesh Kolihttp://www.itechempires.com
Yogesh Koli is a software engineer & Blogger lives in India. He's driven by an addiction to learning and a love for adventure. he has 6+ years of experience working with the front-end and back-end web application development.

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

Notify of

Tutorials You May Like!

- Advertisement -