Oracle PHP PDO 异常:找不到驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15514665/
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 09:22:59  来源:igfitidea点击:

Oracle PHP PDO exception: could not find driver

phporaclepdo

提问by kaizenCoder

I'm trying to hack together a script to connect to a remote oracle database and execute a simple query

我正在尝试编写一个脚本以连接到远程 oracle 数据库并执行一个简单的查询

Through extensive searches I found the following script:

通过广泛的搜索,我找到了以下脚本:

<?

$tns = "
    (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = bogus.com.au)(PORT = 1521))
        (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = myDB )
        )
    )
";


$pdo_string = 'oci:dbname='.$tns;

try {
    $dbh = new PDO($pdo_string, 'test', 'fake');
} catch (PDOException $e) {
    echo "Failed to obtain database handle: " . $e->getMessage();
    exit;
}

$query = "SELECT * FROM someTable";

$stmt = $dbh->prepare($query);

if ($stmt->execute()) {
    echo "<h4>$query</h4>";
    echo "<pre>";
    while ($row = $stmt->fetch()) {
        print_r($row);
    }
    echo "</pre>";
}

?>

However I'm getting the error could not find driver. So I did:

但是我收到了错误could not find driver。所以我做了:

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

Which returned:

哪个返回:

mysql
odbc
sqlite

That tells me that I do have the driver installed, yes?

这告诉我我确实安装了驱动程序,是吗?

What am I doing wrong? (Admittedly I have little to no knowledge of PHP with Oracle databases so maybe I'm missing the blatantly obvious..)

我究竟做错了什么?(诚​​然,我对 Oracle 数据库中的 PHP 知之甚少,所以也许我错过了明显的..)

回答by Emery King

You have to install Oracle adapter in PDO:

您必须在 PDO 中安装 Oracle 适配器:

http://php.net/manual/en/ref.pdo-oci.php

http://php.net/manual/en/ref.pdo-oci.php

回答by Ibrahim.I

You have to configure your server to enable the PDO_OCI extension.

您必须配置您的服务器以启用 PDO_OCI 扩展。

Go to php.iniand find the line extension=php_pdo_oci.dlland remove the comma ;from its start then restart your apache service.

转到php.ini并找到该行extension=php_pdo_oci.dll;从其开头删除逗号,然后重新启动您的 apache 服务。