Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have 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 have uncommented and set 'php.ini' file according to other question & answer about similar problem.

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

but, there was no particular change in the situation. Still could not find drivers.

However, When I type 'php -m' and 'php -i', I can find PDO is enable.

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 they cannot find PDO drivers? Please Help me. Thank u.

like image 773
Naing Avatar asked Nov 10 '22 20:11

Naing


1 Answers

For me, I found that the extension (extension=php_pdo_mysql.dll) had been commented out in php.ini.

Removed the ';' from the start of the line, restarted services and XAMPP and all good.

like image 153
user2235265 Avatar answered Nov 14 '22 22:11

user2235265