Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  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.

like image 826
Yuri Scarbaci Avatar asked Nov 14 '12 08:11

Yuri Scarbaci


People also ask

How do I install PDO drivers?

Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.

Does PDO work with MySQL?

PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries.

How do you connect to a MySQL database using PDO?

A PDO database connection requires you to create a new PDO object with a Data Source Name (DSN), Username, and Password. The DSN defines the type of database, the name of the database, and any other information related to the database if required. These are the variables and values we stated inside the dbconfig.

What is the difference between a PDO and a MySQLi database connection?

MySQLi is a replacement for the mysql functions, with object-oriented and procedural versions. It has support for prepared statements. PDO (PHP Data Objects) is a general database abstraction layer with support for MySQL among many other databases.


1 Answers

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.

like image 185
Jani Hartikainen Avatar answered Oct 16 '22 19:10

Jani Hartikainen