Pdo mysql php linux

Installing PDO driver on MySQL Linux server

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.

6 Answers 6

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.

okay, i looked up in my php.ini file and it looks like pdo in enabled by default, i still need to know if i can use both pdo and mysql_*handlers.

@jonaspas if you are on ubuntu, try updating with sudo apt-get update then run the original install from the answer.

Thanks ryAn_Hdot! But that also didn’t work for me. My solution now: I was running php7 and i had to do sudo apt-get install php-mysql

That’s a good question, but I think you just misunderstand what you read.

Install PDO

The ./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.

so if i wanna use both at the same time i will have to use both the connection methods? what i mean is: i have like 50 pages already running, with a lot of code, it took like a year of developing and i can’t turn back just for 1 page, not now anyway. what i need to do is have those 50 pages run as they are, and this one page i’m writing now using pdo, is it even possible? thanks for your time ^^

Читайте также:  Установка графического драйвера intel linux

refactoring can be usefull if you have to change a lot of code. But yes, if you want yo use both, you have to establish two connections.

is there a easy why to refactore my code? i’m currently working on a work i didn’t start my self, it was done by another programmer wich left it off, and now i have to adapt to his code. it’s a bit harsh since everyone have his own style, so i would rather leave it as it is for now, since this software was used till now without any problem. thx btw ^^ do i need to close the mysql connection before opening the pdo one, or i can have both open at the same time? ^^

At first install necessary PDO parts by running the command

sudo apt-get install php*-mysql 

where * is a version name of php like 5.6, 7.0, 7.1, 7.2

After installation you need to mention these two statements

extension=pdo.so extension=pdo_mysql.so 

in your .ini file (uncomment if it is already there) and restart server by command

sudo service apache2 restart 

This answer was extremely helpful because it pointed out you need the PHP version number in php*-mysql . I was trying php-mysql and php7-mysql to no avail and then this answer sealed the deal! Thanks!

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

extension=pdo.so extension=pdo_mysql.so 

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/

I didn’t have these lines in my php.ini file. I only have extension=pdo_mysql.dll , so I uncommented that and restarted apache and it worked.

Читайте также:  Какие вирусы в линукс

@user3494047 I guess you are on a windows system. I took the config excample from a linux system. But great that you shared your experience!

Thanks! I must have run a dozen sudo apt-get install. commands and nothing worked, finally adding these two lines to the php.ini did it. Just mentioning the apache server restart command that you run after saving : sudo service apache2 restart . And my php.ini file path was /etc/php/7.0/apache2/php.ini (OS: Lubuntu 16.04, analogous to Ubuntu for these purposes). Run sudo gedit to edit it. (gedit or geany or any text editor on your system)

Thanks for the details. Actually it can be very different where your php.ini is located. You can even overwrite it per project. I updated my answer.

  1. PDO stands for PHP Data Object.
  2. PDO_MYSQL is the driver that will implement the interface between the dataobject(database) and the user input (a layer under the user interface called «code behind») accessing 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. By using this layer, data can be normalized before being inserted into your data structure. (Capitals are Capitals, no leading or trailing spaces, all dates at properly formed.)

But there are a few nuances to this which you might not be aware of.

First of all, up until now, you’ve probably written all your queries in something similar to the URL, and you pass the parameters using the URL itself. Using the PDO, all of this is done under the user interface level. User interface hands off the ball to the PDO which carries it down field and plants it into the database for a 7-point TOUCHDOWN.. he gets seven points, because he got it there and did so much more securely than passing information through the URL.

You can also harden your site to SQL injection by using a data-layer. By using this intermediary layer that is the ONLY ‘player’ who talks to the database itself, I’m sure you can see how this could be much more secure. Interface to datalayer to database, datalayer to database to datalayer to interface.

Читайте также:  Linux mint установка gcc

By implementing best practices while writing your code you will be much happier with the outcome.

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

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

Or check with bitmonkey. There’s a group there I’m sure you could learn a lot with.

Источник

Pdo mysql php linux

Check the system logs to confirm that there are no related errors. You can use ZoomAdmin to check the logs, manager servers, host multiple websites and apps on your servers and more. The apps run in docker containers, to learn more
see ZoomAdmin Features for list of features and demo videos. And you can start with the Free Plan.

Execute the commands above step by step. You can simply hit the copy button to copy the command and paste into the command line interface.
Note: -y flag means to assume yes and silently install, without asking you questions in most cases.

Package Description
Detailed Instructions:
Step 1
Step 2
Step 3

Check the system logs to confirm that there are no related errors. You can use ZoomAdmin to check the logs, manager servers, host multiple websites and apps on your servers and more. The apps run in docker containers, to learn more
see ZoomAdmin Features for list of features and demo videos. And you can start with the Free Plan.

We use cookies to provide better service. For more information please see our Privacy Policy.
By continuing to browse our website, you agree to our use of cookies.

Get connected with us on social networks!
ZoomAdmin

We provide cloud-based platform to easily manage and maintain your servers and apps, using intuitive web interface and modern technology.

Источник

Оцените статью
Adblock
detector