未捕获的异常 'PDOException',错误信息为 '找不到驱动程序'。

11

大家好,我需要你们的帮助

我收到了一个错误

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.

我正在使用118.139.182.107/~rails/HTML/test.php,其中包含PHP版本的所有信息以及PDO库的显示。

我的托管提供商说他们已经安装了PDO,但是我遇到了问题。

我的代码如下:

<?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));

?>

请帮忙..


@Flosculus,您可以解释一下吗?我不知道$dsn是什么。 - Ashish Chaturvedi
我认为这个错误意味着他们安装了PDO,但没有安装它的MySQL驱动程序。 - Barmar
@Barmar 你可以通过访问 http://118.139.182.107/~rails/HTML/test.php 查看我的 php_info。 - Ashish Chaturvedi
1
@Barmar 这意味着PDO仅支持Sqlite而不支持Mysql。 - Ashish Chaturvedi
没错,就是这个意思。你需要向托管提供商请求安装PDO MySQL驱动程序。 - Barmar
显示剩余2条评论
1个回答

27
根据您展示的 phpinfo() 信息,仅安装了 PDO Sqlite 驱动。您需要告诉托管服务提供商安装 PDO MySQL 驱动程序。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接