John Cody
John Cody

Reputation: 51

PDO: Could not find driver php/mysql

i'm having issues connecting to my database on a web host that I have, i'm using the following:

$dsn = 'mysql:host=mysql1.hosting.digiweb.ie;dbname=mydbname';
 $user = 'myusername';
 $password = 'mypassword';

According to the website: Host Name mysql1.hosting.digiweb.ie (ip address)

as the title says i'm getting a could not find driver error, am i entering the host incorrectly i tried entering whats above and also the ip address - Thanks!

Edit:

Here's all my code

<?php

 $dsn = 'mysql:host=localhost;dbname=';
 $user = '';
 $password = '';

try {
  // Connect and create the PDO object
 $dbh = new PDO($dsn, $user, $password);
 $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
 echo 'Database connection failed - ';
 echo $e->getMessage();
 exit;
}


echo 'works';
?>

Upvotes: 5

Views: 30245

Answers (2)

Failo
Failo

Reputation: 31

Change your extension dir to be absolute in php.ini. I changed it from

extension_dir = "ext" 

to

extension_dir = "C:/{PATH TO PHP DIRECTORY}/ext"

and it worked.

Upvotes: 3

echo_Me
echo_Me

Reputation: 37233

go to your php.ini file and uncomment this line

    extension=php_pdo_mysql.dll

and then restart your apache

Upvotes: 5

Related Questions