Hi Friends, Thanks for be with Freewebmentor. Freewebmentor wishes you Happy New Year 2017. This is the my first post in 2017. Today i am going to share very useful thing. If you are a PHP Developer OR your websites/web applications are running on PHP, then keep close attention in this post.

Recently PHP have stop supports the some functions. In this post i will advice to start using PDO instead of PHP MySQL extension. PHP have stop support mysql_query() function, you can use mysqli_query() OR PDO instead of mysql_query().

php-pdo

How to connect database using MYSQLi

Below is the complete example to connect your mysql database using mysqli_query() function.

How to connect database using PDO

Now you have another option to connect your mysql database using PDO(PHP Data Object). I suggest you to use PDO in your php based application. Below is the complete example to connect with database.

PDO (PHP Data Object) tutorials for beginners

How to get data from database using PDO

Now you have a question how to select data from mysql table using PDO. Below example will show the complete code to get data from mysql table using PDO (PHP Data Object).

The Output will something similar to below example: