Reputation: 19347
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";
$this->setupSQLStatement();
}
catch(PDOException $e)
{
echo $e->getMessage();
die();
}
}
It raised the exception "could not find driver". What is the driver and how to use it ?
Upvotes: 1
Views: 9113
Reputation: 1274
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:
;extension=php_pdo_mysql.dll
Remove the ;
, so it looks like this and then retry:
extension=php_pdo_mysql.dll
Also do the same as above with:
;extension=php_pdo.dll
Upvotes: 1
Reputation: 3344
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 :
extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_ibm.dll
;extension=php_pdo_informix.dll
;extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pdo_sqlite_external.dll
;extension=php_pdo_user.dll
On a UNIX environment, replace .dll by .so. Uncomment only adapters that you need (in the above example : MySQL).
Upvotes: 4
Reputation: 4656
PDO::getAvailableDrivers()
Using this you can find available drivers in your server.
Upvotes: 1