Coler234 Coler234 - 1 month ago 10
MySQL Question

Connection falied: could not find driver

I'm on Windows 10 and I'm using WAMP. I am trying to create a login form with prepared PDO statements. Below is the code to my connect.php script that is issuing the error: "Connection failed: could not find driver".

<?php

$server = 'localhost';
$username = 'root';
$password = '';
$db = 'login';

try{
$conn = new PDO("mysqli:host=$server;dbname=$db", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected Successfully";
}catch(PDOException $e){
echo "Connection falied: " . $e->getMessage();
}
?>


This is a list from my php.ini file that shows and DLLs associated with pdo

extension=php_openssl.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pdo_mysql.dll
extension=php_pdo.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_shmop.dll


WAMP says "no dll file" for:
-php_mysqli
-php_pdo

I have the "php_pdo" dll file in wamp/bin/php5.6.25/ and in wamp/bin/php5.6.25/ext/ just in case.
I can't find a download for php_mysqli but I don't think I need that for PDO, though it would be nice to have if anyone has a download link.

So my question is, did I just install the dll file into the wrong directory, or what? I'm not sure what to do, But I just installed WAMP and I can't use PDO. Should I use another client(I'm not sure what they are called).

Answer

I think you have a typo, try mysql instead of msqli:

$conn = new PDO("mysql:host=$server;dbname=$db", $username, $password);

Also from comments:

  1. Try to put this in the php.ini : extension_dir = "c:\php5\ext" and point to the extension
  2. move php_pdo.dll before the other PDO extensions, and restart WAMP