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;"
完整的例子如下:
$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 '
while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
print '
';foreach($row as $item) {
print '
'.($item?htmlentities($item):' ').'';}
print '
';}
print '
';oci_close($conn);
?>