php联接访Oracle是用过oci函数

WBOY
Release: 2016-06-13 13:02:53
Original
967 people have browsed it

php连接访Oracle是用过oci函数

php连接访Oracle是用过oci函数,以下是整理的文档

1.安装Apache和php包

yum install -y httpd php*

2.下载Oracle组件

oracle-instantclient-basic-10.2.0.4-1.i386.rpm

oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm

oracle-instantclient-devel-10.2.0.4-1.i386.rpm

oracle-instantclient-odbc-10.2.0.4-1.i386.rpm

#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组件

http://pecl.php.net/get/oci8-1.4.1.tgz

#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()函数查看

码连接测试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. ?> 

最后通过浏览器浏览页面




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!