Oracle PHP PDO 异常:找不到驱动程序 [英] Oracle PHP PDO exception: could not find driver
问题描述
我正在尝试编写一个脚本来连接到远程 oracle 数据库并执行一个简单的查询
通过广泛的搜索,我找到了以下脚本:
<代码>$tns = "(描述 =(地址 = (协议 = TCP)(主机 = bogus.com.au)(端口 = 1521))(CONNECT_DATA =(服务器 = 专用)(SERVICE_NAME = myDB)))";$pdo_string = 'oci:dbname='.$tns;尝试 {$dbh = new PDO($pdo_string, 'test', 'fake');} catch (PDOException $e) {echo "获取数据库句柄失败:".$e->getMessage();出口;}$query = "SELECT * FROM someTable";$stmt = $dbh->prepare($query);如果 ($stmt->execute()) {echo "<h4>$query</h4>";echo "";while ($row = $stmt->fetch()) {打印_r($row);}echo "</pre>";}?>但是我收到错误
找不到驱动程序
.所以我做到了:foreach(PDO::getAvailableDrivers() as $driver)echo $driver, '<br>';
返回的是:
mysql数据库sqlite
这告诉我我确实安装了驱动程序,是吗?
我做错了什么?(诚然,我对 Oracle 数据库中的 PHP 知之甚少,所以也许我错过了明显的..)
解决方案您必须在 PDO 中安装 Oracle 适配器:
http://php.net/manual/en/ref.pdo-oci.php
I'm trying to hack together a script to connect to a remote oracle database and execute a simple query
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: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..)
解决方案You have to install Oracle adapter in PDO:
http://php.net/manual/en/ref.pdo-oci.php
这篇关于Oracle PHP PDO 异常:找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!