gpt4 book ai didi

php - Oracle PHP PDO 异常 : could not find driver

转载 作者:行者123 更新时间:2023-12-05 05:27:54 29 4
gpt4 key购买 nike

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

通过大量搜索,我发现了以下脚本:

<?

$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>";
}

?>

但是我收到错误找不到驱动程序。所以我做了:

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

返回的是:

mysql
odbc
sqlite

这说明我确实安装了驱动程序,是吗?

我做错了什么? (不可否认,我对 Oracle 数据库的 PHP 知之甚少,所以也许我错过了显而易见的......)

最佳答案

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

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

关于php - Oracle PHP PDO 异常 : could not find driver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15514665/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com