Problem Connecting to HeidiSQL using PDO in Linux Mint 19.3

Codes here !

Moderators: egami, macek, gesf

Post Reply
witgrefe
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 18, 2020 10:37 pm

Sat Apr 18, 2020 10:49 pm

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
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Sun Apr 19, 2020 10:01 am

Have you tried the HeidiSQL community?
witgrefe
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 18, 2020 10:37 pm

Mon Apr 20, 2020 1:17 am

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
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Mon Apr 20, 2020 10:43 am

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: Select all

<?php
phpinfo();
witgrefe
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 18, 2020 10:37 pm

Mon Apr 20, 2020 11:12 pm

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
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Tue Apr 21, 2020 9:40 am

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: Select all

sudo apt update
sudo apt install pdo-mysql
sudo apt update
sudo apt upgrade
then restart your computer
witgrefe
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 18, 2020 10:37 pm

Wed Apr 22, 2020 1:00 am

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
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Wed Apr 22, 2020 8:26 am

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

Code: Select all

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: Select all

sudo apt update
sudo apt upgrade
Install MySQL before PHP.
witgrefe
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 18, 2020 10:37 pm

Wed Apr 22, 2020 11:06 pm

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
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Thu Apr 23, 2020 9:11 am

Hopefully someone will find your solution if they have the same problem :)
Post Reply