Reputation: 51
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
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
Reputation: 37233
go to your php.ini file and uncomment this line
extension=php_pdo_mysql.dll
and then restart your apache
Upvotes: 5