0

I'm trying to connect php to my MySQL databse, but I've a "could not find driver" message. I'm working on Windows and I use php -s localhost:9000

This is the code I'm using to connect my database :

$servername = "localhost";
$port = "3306";
$username = "root";
$password = "password";
$dbname = "mydb";
$dsn = "mysql:host=" . $servername . ";port=" . $port . ";dbname=" . $dbname;

try {
    
    $pdo = new PDO($dsn, $username, $password);
    $retour["connected"] = true;
    $retour["message"] = "Connexion à la base de données réussie";
    
    // set the PDO error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
    $retour["connected"] = false;
    $retour["message"] = "Erreur lors de la tentative de connexion";
} ?> 

Just to be sure, $dbname should be my MySQL schema's name, right ?

About the missing driver, I've tried to those things:

  • Uuncomment extension_dir="ext" on both lines in my php.ini.
  • Same for extension=pdo_mysql.
  • php -v is giving me the same version I'm using.
  • phpinfo() is giving me a "Configuration File (php.ini) Path => "
  • I've tried to copy my php.ini at C:/Windows

I'm out of ideas. Thanks in advance for your help !

1 Answers1

-1

In your browser, use localhost:3306 or localhost instead of localhost:9000.

  • My php server is running at localhost:9000, there is no problem with it. The problem is the connection to the database. – Leonard Ebel Jun 10 '22 at 09:56