1

Possible Duplicate:
mysqli or PDO - what are the pros and cons?
PHP PDO and MySQLi

I recently asked a question that resulted in people telling me to use "PDO" over MySQL. Why is that? What advantages does it have over the other?

Community
  • 1
  • 1
  • 1
    It's `PDO`, standing for PHP Data Objects, not `POD`. – nickb May 29 '12 at 20:01
  • For clarification, you'd still be accessing a MySQL database. PDO is just another (better) way to access it - for example you get query parameterisation that you can't do with the standard `mysql` functions. – halfer May 29 '12 at 20:05
  • PDO is an library that provides object oriented abstraction for interaction with different database engines (MySQL, PostgreSQL, and so on), so you use only one API to handle all connections. Furthermore, PDO supports prepared statements, which mean that instead of entering all parameters in SQL queries you put only placeholders and then bind proper values when trying to execute query. This prevents or at least makes it really hard to perform SQL injection attack on your application. – Tomasz Kowalczyk May 29 '12 at 20:08
  • Here is very nice tutorial on PDO http://a2znotes.blogspot.in/2014/09/introduction-to-pdo.html – RN Kushwaha Sep 12 '14 at 17:37

3 Answers3

8

The mysql_* functions are no longer maintained and community has begun the deprecation process. Instead you should learn about prepared statements and use either PDO or MySQLi.

If you cannot decide, this article should help you choose. Though, you should know, that PDO is able to work with different kinds of RDBMS, while MySQLi is made for a specific one.

In case you decide to go with PDO, it's recommended you follow this tutorial.

vascowhite
  • 18,120
  • 9
  • 61
  • 77
0

For one, mysql_* functions will be deprecated.

Secondly, PDO functions are easier to use and can be used with non-MySQL databses.

Also worth noting might be that you don't have to use PDO, mysqli is fine as well!

Jeroen
  • 13,056
  • 4
  • 42
  • 63
  • 1
    Correction : they _will be deprecatred_. Such a deprecation is not yet mentioned in the [MySQL extension manual](http://us2.php.net/manual/en/book.mysql.php) – Michael Berkowski May 29 '12 at 20:02
0

PDO provides you with uniform methods to access various kinds of database. Having a quick look on the Internet could be beneficial.

vascowhite
  • 18,120
  • 9
  • 61
  • 77
zessx
  • 68,042
  • 28
  • 135
  • 158