PHP PDO vs normal mysql_connect

前端 未结 12 993
盖世英雄少女心
盖世英雄少女心 2020-11-27 12:15

Should I use php PDO or normal mysql_connect to execute database queries in PHP?

Which one is faster?

One of the big benefits of PDO is that the interface is

12条回答
  •  长情又很酷
    2020-11-27 12:31

    I don't think speed is what people are looking for when they are using PDO -- I don't know if there is a difference, and I honnestly don't care : as long as I'm doing a couple of queries to a database when generating a page, a couple of milliseconds on the PHP side will not change anything.

    There are two/three great things with PDO, compared to mysql_* :

    • More or less constant interface accross databases ; better than using mysql_*, pg_*, oci_*, ...
    • Object-Oriented API (mysqli_* has an OO-API, but not mysql_*)
    • Support new features of MySQL >= 4.1 (same as mysqli_*, but not mysql_*, again)

    BTW : I'm generally using PDO -- either "by hand", or as it's integrated in / used by Zend Framework and/or Doctrine.


    As a sidenote : Even if you are not going to use PDO, note that using mysqli instead of mysql is recommended.

    See this page of the PHP manual, about that.

提交回复
热议问题