php客户端连接Oracle数据库

php连接访问Oracle是用过oci函数,以下是整理的文档
1.安装Apache和php包 
 
 
  1. yum install -y httpd php* 
2.下载Oracle组件
#rpm -ivh oracle-instantclient*(四个组件全部安装上)
此时会生成/usr/lib/oracle/10.2.0.4/client/lib/目录
3.修改/etc/ld.so.conf文件
#vim /etc/ld.so.conf
追加以下内容
/usr/lib/oracle/10.2.0.4/client/lib/
#ldconfig(执行命令)
4.下载OCI8组件
#tar zxvf oci8-1.4.1.tgz
5.编辑OCI8模块
#cd oci8-1.4.1
#phpize(执行命令)
#./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client/lib/
#make install
成功后系统会提示你:oci8.so已经成功放入/usr/lib/php/modules/目录中
6.修改php.ini文件
#vim /etc/php.ini
追加以下内容
extension=oci8.so
7.重启Apache服务
service httpd restart
8.使用phpinfo()函数查看

9.编辑php代码连接测试oracle数据库

 
 
  1. <?php 
  2.  
  3. $conn = oci_connect('scott', 'oracle', '192.168.12.133/orcl');  
  4.  
  5. if (!$conn) {  
  6.  
  7. $e = oci_error();  
  8.  
  9. print htmlentities($e['message']);  
  10.  
  11. exit;  
  12.  
  13. }  
  14.  
  15. $query = 'select ename,sal from scott.emp';  
  16.  
  17. $stid = oci_parse($conn, $query);  
  18. if (!$stid) {  
  19.  
  20. $e = oci_error($conn);  
  21.  
  22. print htmlentities($e['message']);  
  23.  
  24. exit;  
  25.  
  26. }  
  27.  
  28. $r = oci_execute($stid, OCI_DEFAULT);  
  29. if(!$r) {  
  30.  
  31. $e = oci_error($stid);  
  32.  
  33. echo htmlentities($e['message']);  
  34.  
  35. exit;  
  36.  
  37. }  
  38.  
  39. print '<table border="1">';  
  40.  
  41. while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {  
  42.  
  43. print '<tr>';  
  44.  
  45. foreach($row as $item) {  
  46.  
  47. print '<td>'.($item?htmlentities($item):' ').'</td>';  
  48.  
  49. }  
  50.  
  51. print '</tr>';  
  52.  
  53. }  
  54.  
  55. print '</table>';  
  56.  
  57. oci_close($conn);  
  58.  
  59. ?> 

最后通过浏览器浏览页面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值