PDO: Could not find php / mysql driver

I am having problems connecting to my database on the web host that I have, I use the following:

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

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

as the title says that I get a I can’t find the driver error, I enter the host incorrectly, I tried to log in as above, as well as the ip address - Thanks!

Edit:

Here is 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';
?>
+5
source share
2 answers

go to php.ini file and uncomment this line

    extension=php_pdo_mysql.dll

and then restart apache

+5
source

Change dir extension to absolute value in php.ini. I changed it with

extension_dir = "ext" 

to

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

and he worked.

+3
source

All Articles