php 未捕获的异常“PDOException”,消息“找不到驱动程序”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20950708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:41:47  来源:igfitidea点击:

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

phppdooauth

提问by Ashish Chaturvedi

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.

我正在使用 118.139.182.107/~rails/HTML/test.php 拥有 PHP 版本的所有信息并显示 PDO 库。

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

我的托管提供说他们在其中安装了 PDO 但出现问题

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..

请帮忙..

回答by Barmar

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.

根据phpinfo()你显示的,只安装了 PDO Sqlite 驱动程序。您需要告诉主机提供商安装 PDO MySQL 驱动程序。