我正在尝试将脚本连接到远程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知之甚少,所以也许我错过了明显的明显......)
答案 0 :(得分:2)
您必须在PDO中安装Oracle适配器:
答案 1 :(得分:0)
您必须配置服务器以启用PDO_OCI扩展。
转到php.ini
并找到行extension=php_pdo_oci.dll
并从开头删除逗号;
,然后重新启动您的apache服务。