1

I decided to continue an old project that I had abandoned some time ago due to many mistakes. With new strength I started to remove mistakes but I reached a point where I got stuck. I found with great difficulty that my problem came from the PDO connection to my database and half of my code became unusable. I read on the topic and tried many different ways to solve the problem, but without success. For starters I will say that I use XAMPP, Server version: 10.4.8-MariaDB, Apache / 2.4.41 (Win64) OpenSSL / 1.1.1c PHP / 7.3.1, phpMyAdmin Version information: 5.1.1 (up to date). Since I haven't used XAMPP for a long time and I have Workbench, Postgree and others installed, I had to change the ports of Apache and MySQL. I put a password on the root account in phpMyAdmin because I read that this can help, but then there were more problems, I used this request in phpMyAdmin:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
BY '...';

But in this query it gave me a syntax error and for that I used the one that was successful:

ALTER USER 'root'@'localhost' IDENTIFIED BY '...';

But the problem still exists. I also want to insert the fact that there are 2 connection strings in my project. There is no problem with one, but with the PDO connection string I get this error from the try catch construction:

Connection failed: SQLSTATE [HY000] [2054] The server requested authentication method unknown to the client

I read that the problem may be due to busy ports, but I decided to consult you before I started messing with the XAMPP files. Basically I changed the port to 3308 and the workbench is to 3306 but still when I run XAMPP I get an error message:

Problem detected!
Port 3306 in use by "Unable to open process"!
MySQL WILL NOT start without the configured ports free!
You need to uninstall / disable / reconfigure the blocking application
or reconfigure MySQL and the Control Panel to listen on a different port

However, I still managed to start MySQL.

I decided to write this to get advice and possibly help people with the same problem, because I saw that there are a lot of people who have encountered this.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • 1
    Another process (program) is using port 3306, that's what the message says. To find out, try `netstat -a -b` (see also https://stackoverflow.com/questions/48198/how-can-you-find-out-which-process-is-listening-on-a-tcp-or-udp-port-on-windows) – Honk der Hase Sep 18 '21 at 08:11
  • basically i fixed this message from XAMPP via httpd.conf and my.ini. Then through Config. But the main mistake is: Connection failed: SQLSTATE [HY000] [2054] The server requested authentication method unknown to the client @LarsStegelitz – ilian_dimitrov Sep 18 '21 at 13:20

1 Answers1

0

I found a solution to my problem thanks to @iambpn -> https://github.com/laradock/laradock/issues/1392. I also have a mysql server installed. I changed my connection string in the same way as the post from Aug 23, 2019 by putting the host. my solution looks like this:

$host = "127.0.0.1:3308";
$dbname = "inventory";
$user = "root";
$password = "------";

try {
    $dsn = 'mysql:host='.$ host.';dbname ='.$dbname;
    $connect = new PDO ($dsn,$user,$password);
    $connect->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    return $connect;
} catch (PDOException $e) {
    echo 'Connection failed:'.$e->getMessage();
    exit;
}

but before that the XAMPP ports must be changed if SQL server is installed!