php7配置oracle11g,怎么配置连接上

如题所述

php配置oracle非常的简单需吧php.ini文件中的配置,去掉 ;extention = php_oci8.dll,去掉前面的分号,重启apache就可以了
oracle数据库建立链接,代码如下:
1:
$conn =
oci_connect('username','password',"(DEscriptION=(ADDRESS=(PROTOCOL
=TCP)(HOST=192.168.1.100)(PORT = 1521))(CONNECT_DATA =(SID=test)))");
2:
$conn = oci_connect('username','password','192.168.1.100/test');

3.Oracle 连接方法
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"
完整的例子如下:
<?php
$conn = oci_connect('hr', 'hr', 'orcl'); // 建立连接
if (!$conn) {
$e = oci_error();
print htmlentities($e['message']);
exit;
}
$query = 'SELECT * FROM DEPARTMENTS'; // 查询语句
$stid = oci_parse($conn, $query); // 配置SQL语句,准备执行
if (!$stid) {
$e = oci_error($conn);
print htmlentities($e['message']);
exit;
}
$r = oci_execute($stid, OCI_DEFAULT); // 执行SQL。OCI_DEFAULT表示不要自动commit
if(!$r) {
$e = oci_error($stid);
echo htmlentities($e['message']);
exit;
}
// 打印执行结果
print '<table border="1">';
while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
print '<tr>';
foreach($row as $item) {
print '<td>'.($item?htmlentities($item):' ').'</td>';
}
print '</tr>';
}
print '</table>';
oci_close($conn);
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-09
我也遇到这个问题,网上没找到答案, 现在解决了:
版本是PHPSTUDY中PHP-7.2.10-NTS 32位,客户端也用11g32位, 需要到windows.php.net
下载php_oci8-2.1.8-7.2-nts-vc15-x86.zip取其中的php_oci8_11g.dll到PHP的ext目录中。
其他正常修改php.ini加载扩展模块,重启就OK了。
相似回答