Installing PDO driver on MySQL Linux server
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.
PHP 7 RC3: How to install missing MySQL PDO
Since eggyal didn't provided his comment as answer after he gave right advice in a comment - i am posting it here: In my case I had to install module php-mysql
. See comments under the question for details.
Why are PHP 7 PDO drivers missing?
When creating the connection, your DSN has localhost
as the database type...
$dbh = new PDO('localhost:host=$servername;dbname=test', $username, $password);
from the manual
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
Also as you use single quotes, the servername will not be replaced, so use
$dbh = new PDO("mysql:host=$servername;dbname=test", $username,
How to install pdo driver in php docker image?
The official repository of PHP has a script called
docker-php-ext-install
https://github.com/docker-library/php/tree/master/5.6
You forgot to install the extension needed to run the PDO.
Try do create a docker image like this:
FROM php:5.6-apache
# PHP extensions
RUN docker-php-ext-install pdo pdo_mysql
Installing PDO driver for MySQL
You might find this PHP PDO tutorial helpful.
Related Topics
Pdo Were Rows Affected During Execute Statement
Simple PHP Echo Code Not Working
Simplexml Get Element Content Based on Attribute Value
Commenting Interpreted Code and Performance
How to Search Array for Multiple Values in PHP
Sending/Displaying a Base64 Encoded Image
How to Pass an Array of Pdo Parameters Yet Still Specify Their Types
What Means Call to a Member Function on Boolean and How to Fix
Convert PHP Array String into an Array
Using Return in Ternary Operator
Multiple Http Get Parameters with the Same Identifier
Browscap Ini Directive Not Set