我正在尝试编写一个脚本以连接到远程 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>";
}
?>
但是我得到了错误could not find driver
。所以我做了:
foreach(PDO::getAvailableDrivers() as $driver)
echo $driver, '<br>';
哪个返回:
mysql
odbc
sqlite
这告诉我我确实安装了驱动程序,是吗?
我究竟做错了什么?(诚然,我对使用 Oracle 数据库的 PHP 知之甚少,所以也许我错过了明显的..)