0

I have tryed every solution i found around here.. nothing works..

i am using Eclipse and Xampp. Trying to connect MySQL to the PHP script..

when i type phpinfo() i can see the PDO drivers are there: printscreen

$dns = "mysql : dbname =DataBase; localhost";
$user = "root";
$password = null;

try {
    $conn = new PDO($dns, $user, $password);
} catch (PDOException $e) {
    echo 'Erro: ', $e->getMessage();
}

All i get is could not find driver

the needed lines are uncommented on php.ini

;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
Henrique
  • 3
  • 2
  • Try the second answer from this post: https://stackoverflow.com/questions/27361413/laravel-migration-error-using-xampp-pdoexception-could-not-find-driver – catcon Sep 11 '19 at 01:31

2 Answers2

0

a windows server you can add or uncomment the following lines in your php.ini

extension=php_pdo.dll
extension=php_pdo_mysql.dll

OR:

extension=pdo.dll
extension=pdo_mysql.dll

restart your XAMPP.

Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49
0

Its not about php.ini or anything related to that matter. You do not need to install anything or turn on stuff related to PDO when it comes to XAMPP, its installed and turned on already.

It's just you're not putting in the correct driver on the dsn:

$dns = "mysql:host=localhost;dbname=DataBase";

Just follow the format, no need for anything fancy.

mysql : dbname =DataBase; localhost
     ^ ^ // why do you need a space? what for?
Kevin
  • 41,694
  • 12
  • 53
  • 70
  • Looks like it worked! i got another error, related to the "SQLSTATE[HY000] [2054] The server requested authentication method unknown to the clientt". But no longer error with the driver. I didn't know the spaces could affect it. I used them just to keep it a bit more readable. I will make a search on the other error to solve it. Thanks Kevin. – Henrique Sep 16 '19 at 20:46