Take the 2-minute tour ×

In my PHP code I run this code :

private function dbConnection() {
        if (!is_resource($this->connessione))
            try {
                    $this->connessione = new PDO($this->db_type.":dbname=".$this->db_name.";host=".$this->db_server, $this->db_username, $this->db_pass );
                    //echo "PDO connection object created";
            catch(PDOException $e)
                    echo $e->getMessage();

It raised the exception "could not find driver". What is the driver and how to use it ?

share|improve this question
What's your PHP version? You should have at least PHP 5.1. –  simone Nov 26 '12 at 9:16
I use w.a.m.p. 5 -> wamp5 info file shows : PHP version 5.2.1 ; Extensions chargées:...,PDO,... . –  pheromix Nov 26 '12 at 9:17
What's the value of $this->db_type? –  jackflash Nov 26 '12 at 9:17
After die-ing I got $this->db_type = mysql –  pheromix Nov 26 '12 at 9:19

3 Answers 3

PDO comes with a core extension, and many "adapters" for some DBMS (MySQL, PostgreSQL, Oracle, SQLite...).

These adapters are additional extensions that you need to enable in php.ini, like this :


On a UNIX environment, replace .dll by .so. Uncomment only adapters that you need (in the above example : MySQL).

share|improve this answer
I uncommented the lines but I always got could not find driver ! –  pheromix Nov 26 '12 at 9:42

Using this you can find available drivers in your server.

share|improve this answer
After making print_r , it shows : Array ( [0] => sqlite [1] => sqlite2 ). So how to make the connection ? –  pheromix Nov 26 '12 at 9:31
$pdo = new PDO('sqlite:/path/to/db/xyz.db'); –  som Nov 26 '12 at 9:33

Add the following and check it outputs a 'mysql' line.

foreach(PDO::getAvailableDrivers() as $driver)
    echo $driver, '<br>';

If it doesn't then open php.ini and find:


Remove the ;, so it looks like this and then retry:


Also do the same as above with:

share|improve this answer

Your Answer


