sanoj lawrence sanoj lawrence - 1 month ago 8
PHP Question

could not find driver in wamp php after run

am using following code to connect to database

//database credentials
define('DBHOST', 'localhost');
define('DBUSER', 'sanoj');
define('DBPASS', '123456');
define('DBNAME', 'test');

//application address
define('DIR', 'http://www.blogtom.com/');
define('SITEEMAIL', 'sanoj@gmail.com');

try {

//create PDO connection
$db = new PDO("mysql:host=" . DBHOST . ";port=3306;dbname=" . DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->exec("SET NAMES 'utf8';");
} catch (PDOException $e) {
//show error
echo '<p class="bg-danger">' . $e->getMessage() . '</p>';
exit;


after i run my php file from netbeans ide i get nothing except this

could not find driver


i tried all method checking
php.ini
file

and even read this http://stackoverflow.com/a/2852997/3836908 tofind some solution
but cant find whats wrong

i used this code in PC it worked well but when i try this on my laptop i get this error how can i solve this problem

am using windows 64bit
but previouly i used 32bit

Answer

Sorry for bad english!

Create a file named info.php with this content:

<?php
phpinfo();
?>

Save and put in your server root.
Access http://localhost/info.php
See what PDO Drivers are loaded (CTRL + F and type PDO drivers).
MySql PDO Driver need to be loaded like this: pdo mysql

If you don't see mysql on PDO drivers, you should edit php.ini and add extension=pdo_mysql.dll
Restart your Apache and try again in info.php

PS: Certify that you have the pdo_mysql.dll in your PHP extensions folder.