PHP PDO "could not find driver" with php 5.5.21 / Apache 2.4 / MySQL 5.6.22 on windows

I have a simple .php file with PDO

<?php
// DB connection info
$host = "localhost";
$user = "root";
$pwd = "1234";
$db = "registration";
try{
    $conn = new PDO( "mysql:host=$host;dbname=$db", $user, $pwd);
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    $sql = "CREATE TABLE registration_tbl(
                id INT NOT NULL AUTO_INCREMENT,
                PRIMARY KEY(id),
                name VARCHAR(30),
                email VARCHAR(30),
                date DATE)";
    $conn->query($sql);
}
catch(Exception $e){
    die(print_r($e));
}
echo "<h3>Table created.</h3>";
?>

and when I execute this php file, I can see this error message.

PDOException Object ( [message:protected] => could not find driver [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\Apache24\htdocs\registration\createtable.php [line:protected] => 8 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\Apache24\htdocs\registration\createtable.php [line] => 8 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=localhost;dbname=registration [1] => root [2] => 1234 ) ) ) [previous:Exception:private] => [errorInfo] => ) 1

So, I uncommented and installed the file "php.ini" in accordance with other questions and answers about a similar problem.

extension=php_pdo_mysql.dll
extension_dir = "c:/php/ext" (absolute Path)

but there were no significant changes in this situation. Still unable to find drivers.

However, when I type "php -m" and "php -i", I can find the PDO resolved.

php -m

[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
ereg
filter
ftp
hash
iconv
json
libxml
mcrypt
mhash
mysqlnd
odbc
pcre
PDO
pdo_mysql
Phar
Reflection
session
SimpleXML
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

php -i

pcre.backtrack_limit => 1000000 => 1000000
pcre.recursion_limit => 100000 => 100000

PDO

PDO support => enabled
PDO drivers => mysql

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb10
57292d73b928b8c5c77 $

Phar

Phar: PHP Archive support => enabled
Phar EXT version => 2.0.2
Phar API version => 1.1.1
SVN revision => $Id: cc0fad28eb9ea42466f756c3b5fc22c764e32690 $
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => disabled (install pecl/bz2)
OpenSSL support => disabled (install ext/openssl)

Why can't they find PDO drivers? Please, help. Thank.

+4
source share
3 answers

, (extension = php_pdo_mysql.dll) php.ini.

';' , XAMPP .

+1

pdo_mysql, php.ini phpinfo(). , php.ini.

0

What worked for me:

  • first - uncomment extensions
  • second - change the variable extension_dirtophp.ini
0
source

All Articles