Installing PDO driver on MySQL Linux server
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:
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-mysqlstring...
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
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.
Verified Answer (179 Votes) ✓
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.
Answer #2 (25 Votes)
That's a good question, but I think you just misunderstand what you read.
./config --with-pdo-mysql is something you have to put on only if you compile your own PHP code. If you install it with package managers, you just have to use the command line given by Jany Hartikainen:
sudo apt-get install php5-mysql and also
sudo apt-get install pdo-mysql
Compatibility with mysql_
Apart from the fact mysql_ is really discouraged, they are both independent. If you use PDO mysql_ is not implicated, and if you use mysql_ PDO is not required.
If you turn off PDO without changing any line in your code, you won't have a problem. But since you started to connect and write queries with PDO, you have to keep it and give up mysql_.
Several years ago the MySQL team published a script to migrate to MySQLi. I don't know if it can be customised, but it's official.
Answer #3 (15 Votes)
Basically the answer from Jani Hartikainen is right! I upvoted his answer. What was missing on my system (based on Ubuntu 15.04) was to enable PDO Extension in my php.ini
restart the webserver (e.g. with "sudo service apache2 restart") -> every fine :-)
To find where your current active php.ini file is located you can use phpinfo() or some other hints from here: https://www.ostraining.com/blog/coding/phpini-file/