Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO: Could not find driver php/mysql

Tags:

php

mysql

pdo

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';
?>
like image 208
John Cody Avatar asked Feb 10 '13 13:02

John Cody


People also ask

How do I install PDO drivers?

Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.

What is PDO in php MySQL?

PHP PDO is a database access layer that provides a uniform interface for working with multiple databases. PDO simplifies the common database operations including: Creating database connections. Executing queries using prepared statements. Calling stored procedures.

What is PDO driver?

Introduction ¶ PDO_MYSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MySQL databases. PDO_MYSQL uses emulated prepares by default.


2 Answers

go to your php.ini file and uncomment this line

    extension=php_pdo_mysql.dll

and then restart your apache

like image 89
echo_Me Avatar answered Oct 02 '22 07:10

echo_Me


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.

like image 29
Failo Avatar answered Oct 02 '22 08:10

Failo