Installing PDO driver on MySQL Linux server

Yuri Scarbaci picture Yuri Scarbaci · Nov 14, 2012 · Viewed 370.4k times · Source

I was suggested, not long ago, to change my code to use PDO in order to parameterize my queries and safely save HTML in the database.

Well, here are the main problems:

  1. I looked at http://php.net/manual/en/ref.pdo-mysql.php, and I don't really get where I should put that $ ./configure --with-pdo-mysql string...

  2. The site I'm building actually only requires PDO for one page. While I may consider re-writing it, it would take a while and I need the pages to be running soon, so I can't turn off MySQL completely. If I do install PDO, will I still be able to use mysql_* handlers?

The server in question is running PHP Version 5.4.6-1ubuntu1 and Apache/2.2.22 (Ubuntu). I'm also running a phpMyAdmin database, if it matters.

Answer

Jani Hartikainen picture Jani Hartikainen · Nov 14, 2012

On Ubuntu you should be able to install the necessary PDO parts from apt using sudo apt-get install php5-mysql

There is no limitation between using PDO and mysql_ simultaneously. You will however need to create two connections to your DB, one with mysql_ and one using PDO.