Why PDO ?

PHP Data Object [PDO] has many reason for you to get started.  mysql_* functions are now old. Now mysql_* will always leave Deprecated warning.

  1. Well any way, mysql_ doesn't support modern SQL database concepts such as prepared statements, stored procs, transactions etc... and
  2. it's method for escaping parameters with mysql_real_escape_string and concatenating into SQL strings is error prone and with some character set hackable.
  3. The other issue with mysql_* is that it is no more maintained. which mean things like security vulnerabilities or any other bug  will not be fixed,  it may stop working altogether with newer versions of MySQL.
  4. Also lately the PHP community have completely remove mysql_* from php7 , which means you will  no longer will be able to use mysql_ function in php7.

Benefits of PDO 

  1. PDO is a Database Abstraction Layer
  2. It is widely known that PDO offers one end channel to access many different databases. Although this is an amazing option, but it doesn't make much sense where one driver is going to be used in whole project.
  3. PDO is more productive, and Safe from sql injection and is much cleaner.
  4. PDO also has different drivers for different SQL database vendors which will allow you to easily use other vendors without having to relearn a different interface. (though you will have to learn slightly different SQL probably).
  5. Instead of concatenating escaped strings into SQL, in PDO you bind parameters which is an easier and cleaner way of securing queries.
  6. Binding parameters also allow for a performance increase when calling the same SQL query many times with slightly different parameters.
  7. PDO also has multiple methods of error handling. The biggest issue I have seen with mysql_* code is that it lacks consistent handling, or no handling at all! With PDO in exception mode, you can get consistent error handling which will end up saving you loads of time tracking down issues.
  8. PDO is enabled by default in PHP installations now, however you need two extensions to be able to use PDO: PDO, and a driver for the database you want to use like pdo_mysql. Installing the MySQL driver is as simple as installing the php-mysql package in most distributions.
  9. PDO abstracts database API along with basic operations which could have been repeated hundreds of times in every application without PDO.

The real PDO benefits are:

  • Security .. Security and Security 
  • Routine Operation (many helper functions to automate routine operations)
  • Usability & Reusability (unified API to access multitude of databases, from SQLite to Oracle)

When there is Security Guaranteed, Why to see Elsewhere ? Let's Get Started using PDO now.

Some of the content has been taken from php.net and wikipedia.com website.

Loading ...

Related Results :

  1. Why PDO ?
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author