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.
- Well any way, mysql_ doesn't support modern SQL database concepts such as prepared statements, stored procs, transactions etc... and
- it's method for escaping parameters with
mysql_real_escape_stringand concatenating into SQL strings is error prone and with some character set hackable.
- 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.
- 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
- PDO is a Database Abstraction Layer.
- 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.
- PDO is more productive, and Safe from sql injection and is much cleaner.
- 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).
- Instead of concatenating escaped strings into SQL, in PDO you bind parameters which is an easier and cleaner way of securing queries.
- Binding parameters also allow for a performance increase when calling the same SQL query many times with slightly different parameters.
- 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.
- 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.
- 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.
Related Results :
- 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.