Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught exception 'PDOException' with message 'could not find driver'

Tags:

php

oauth

pdo

Hi All I need Your Help

I got error

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /home/rails/public_html/newidenty/server.php:12 Stack trace: 
#0 /home/rails/public_html/newidenty/server.php(12): PDO->__construct('mysql:dbname=ra...', 'rails_identy', 'rails_identy') 
#1 /home/rails/public_html/newidenty/registration.php(2): include('/home/rails/pub...') 
#2 {main} thrown in /home/rails/public_html/newidenty/server.php on line 12.

I am using 118.139.182.107/~rails/HTML/test.php Have all Infromation of PHP Version and also showing PDO Library.

My Hosting Provide saying they install PDO in it but Getting Problem

My Code is

<?php
    $dsn      = 'mysql:dbname=*****;host=localhost';
    $username = '*****';
    $password = '*****';

    // error reporting (this is a demo, after all!)
    ini_set('display_errors',1);error_reporting(E_ALL);

    // Autoloading (composer is preferred, but for this example let's just do this)
    require_once('oauth2-server-php/src/OAuth2/Autoloader.php');
    OAuth2\Autoloader::register();
    $PDO = new PDO("mysql:dbname=*****;host=localhost",$username,$password);
    // $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
    $storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));

    // Pass a storage object or array of storage objects to the OAuth2 server class
    $server = new OAuth2\Server($storage);

    // Add the "Client Credentials" grant type (it is the simplest of the grant types)
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));

    // Add the "Authorization Code" grant type (this is where the oauth magic happens)
    $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));

?>

Please help..

like image 867
Ashish Chaturvedi Avatar asked Jan 06 '14 13:01

Ashish Chaturvedi


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.

Could not find driver error php?

If you see "PDOException : could not find driver" in your error logs, that means the SQLite PDO driver is not installed on your server. The SQLite PDO driver is listed as a prerequisite in the help article " Verify your prerequisites".

What is Pdo_mysql?

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. MySQL 8. When running a PHP version before 7.1. 16, or PHP 7.2 before 7.2.


1 Answers

According to the phpinfo() you showed, only the PDO Sqlite driver is installed. You need to tell the hosting provider to install the PDO MySQL driver.

like image 167
Barmar Avatar answered Oct 13 '22 17:10

Barmar