Problem Connecting to HeidiSQL using PDO in Linux Mint 19.3

A

Anonymous

Guest
I am trying to connect to a HeidiSQL db using php PDO on a linux machine. I cannot. This is the code I am using:

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";

try {
$conn = new PDO("mysql:host=$severname;dbname=$db", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e) {
echo "Connection failed:". '</br>' . $e->getMessage();
}
The error returned is: could not find driver

Can someone help please
 
Yes, but no response, also the Linux forum, also no response. I have spent hours on the internet trying to resolve this issue but no luck. Is it possible to use pdo to connect to the Mysql server on a Linux 19.3 machine?

Regards

chris murray
 
Is it possible to use pdo to connect to the Mysql server on a Linux 19.3 machine?

Yes.

Have you checked that MySQL is installed and connected correctly?

Check by running this:
Code:
<?php
phpinfo();
 
I have uninstalled and reinstallled mysql twice, I think it is installed correctly. There is no mention of mysql in the phpinfo() listing. The database has been imported from a windows 10 machine and I can open it via Heidisql and also from the Linux terminal. The error returned when trying to open it through firefox and pdo is "could not find driver r".

Regards

chris murray
 
PHP needs to connect to MySQL this seems to be missing at the moment, this is why you would normally install MySQL first and them MySQL you can try this using your command line:
Code:
sudo apt update
sudo apt install pdo-mysql
sudo apt update
sudo apt upgrade

then restart your computer
 
The problem is, I cannot install pdo-mysql even though the file is where it should be.

This is the error in the error log when the computer is rebootrd:

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20190902/pdo_mysql (/usr/lib/php/20190902/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0

Regards

chris murray
 
You may need to remove the packages before you can install them again.

Code:
sudo apt remove --purge mysql
sudo apt remove --purge php.*
sudo service apache2 stop
sudo apt remove apache2*
sudo apt purge apache2 apache2-utils apache2.2-bin apache2-common
sudo apt autoremove
sudo apt autoclean

Power down your machine and start it back up

run the following
Code:
sudo apt update
sudo apt upgrade

Install MySQL before PHP.
 
Hello,

thanks very much for your patience with me and the help you have offered, it was greatly appreciated. I stumbled over 3 files which needed to be modified, namely:
/usr/lib/php/7.4/php.ini-development
/usr/lib/php/7.4/php.ini-production
/usr/lib/php/7.4/php.ini-production.cli
These files were never visible through explorer (I even tried show hidden files) but were found when I searched for php.ini. I activated the commented out extensions that I needed on all three files and lo-and-behold, the problem was fixed. It was probably not necessary to do that on all three, I am sure one would have been enough but which one. I will perhaps later experiment and find out which one but not now.

Thanks again
chris murray
 
Hopefully someone will find your solution if they have the same problem :)
 
Back
Top