Install PDO driver on MySQL Linux server

Recently, I was asked to change my code to use PDO to parameterize my queries and safely store HTML in the database.

Well, here are the main problems:

  • I looked at http://php.net/manual/en/ref.pdo-mysql.php and I really don't understand where I should put this line $ ./configure --with-pdo-mysql ...

  • On the site that I create, in fact, only a single page PDO is required. Although I might think about re-writing, it will take some time, and I need the pages to work soon, so I cannot completely disable MySQL. If I really install PDO, can I use mysql_* handlers?

The server running the server runs PHP version 5.4.6-1ubuntu1 and Apache / 2.2.22 (Ubuntu). I also run the phpMyAdmin database if that matters.

+83
php mysql pdo install phpmyadmin
Nov 14 '12 at 8:11
source share
6 answers

On Ubuntu, you can install the necessary PDO parts from apt using sudo apt-get install php5-mysql

There are no restrictions between using PDO and mysql_. However, you need to create two connections to your database: one with mysql_ and one using PDO.

+162
Nov 14 '12 at 8:14
source share

This is a good question, but I think you just misunderstand what you are reading.

Install PDO

./config --with-pdo-mysql is what you only need to wear if you compile your own PHP code. If you install it with package managers, you just need to use the command line specified by Jany Hartikainen: sudo apt-get install php5-mysql as well as sudo apt-get install pdo-mysql

Mysql _ compatibility

Besides the fact that mysql_ is really discouraged, they are both independent. If you use PDO, mysql_ is not involved, and if you use mysql_ PDO, it is not required.

If you disable PDO without changing any line in the code, you will have no problem. But since you started connecting and recording queries using PDO, you need to save it and abandon mysql _.

A few years ago, the MySQL team published a script in the switch to MySQLi . I do not know if it can be configured, but it is official.

+23
Nov 14 '12 at 8:19
source share

In principle, the answer from Jani Hartikainen is right! I supported his answer. What was missing on my system (based on Ubuntu 15.04) was to enable the PDO extension in my php.ini

 extension=pdo.so extension=pdo_mysql.so 

restart the web server (for example, using "sudo service apache2 restart") -> every fine :-)

To find where the 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/

+13
Dec 14 '15 at 9:46
source share
  • PDO stands for PHP data object.
  • PDO_MYSQL is a driver that will implement the interface between the data (database) and the user (the layer under the user interface, called the "code behind"), access to your data object, the MySQL database.

The purpose of using this is to implement an additional layer of security between the user interface and the database. Using this level, data can be normalized before being inserted into your data structure. (Capitals are Capitals, with no leading or trailing spaces, all dates are in the correct form.)

But there are a few nuances to this that you may not have suspected.

First of all, so far you have probably written all your requests in something similar to the URL, and you are passing parameters using the URL itself. Using PDO, all this is done under the user interface level. The user interface transfers the ball to the PDO, which transfers it to the field and puts it into the database for the 7-point TOUCHDOWN .. it gets seven points because it got it there and made it much safer than transferring information to the URL.

You can also pin your SQL injection site using a data layer. Using this middleware layer, which is ONLY a “player” that talks to the database itself, I'm sure you can see how it can be much more secure. Interface for datalayer for database, datalayer for database for datalayer for interface.

and

Using the best practices when writing code, you will be much happier with the result.

Additional sources:

Re: MySQL functions in url php dot net / manual / en / ref dot pdo-mysql dot php

Re: three-tier architecture - adding security to your applications https://blog.42.nl/articles/introducing-a-security-layer-in-your-application-architecture/

Re: Object Oriented Design Using UML If you really want to know more about this, this is the best book on the market, Grady Butch was the father of UML http://dl.acm.org/citation.cfm?id=291167&CFID=241218549&CFTOKEN=82813028

Or check with bitmonkey. There is a group there, I'm sure you could learn a lot.

<P →

If we knew what terminology really means, we don’t need to know anything.

<P →
+7
Aug 27 '13 at 13:22
source share

If you need CockPHP Docker Container with MySQL, for this purpose I created a Docker image! No need to worry about customization. It just works!

This is how I installed the image based on Ubuntu:

https://github.com/marcellodesales/php-apache-mysql-4-cakephp-docker/blob/master/Dockerfile#L8

 RUN docker-php-ext-install mysql mysqli pdo pdo_mysql 

Creating and running your application is just a two-step process (given that you are in the current application directory):

 $ docker build -t myCakePhpApp . $ docker run -ti myCakePhpApp 
0
Oct. 20 '15 at 15:33
source share

First install sudo apt-get install php*-mysql where * is the name of the php version, for example 5.6, 7.0, 7.1, 7.2, and then specify

extension = pdo.so as well as extension = pdo_mysql.so

in your .ini file.

0
Dec 10 '17 at 10:29
source share



All Articles