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()函数查看
- yum install -y httpd php*
9.编辑php代码连接测试oracle数据库
- <?php
- $conn = oci_connect('scott', 'oracle', '192.168.12.133/orcl');
- if (!$conn) {
- $e = oci_error();
- print htmlentities($e['message']);
- exit;
- }
- $query = 'select ename,sal from scott.emp';
- $stid = oci_parse($conn, $query);
- if (!$stid) {
- $e = oci_error($conn);
- print htmlentities($e['message']);
- exit;
- }
- $r = oci_execute($stid, OCI_DEFAULT);
- 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);
- ?>
最后通过浏览器浏览页面
本文出自 “老徐的私房菜” 博客,谢绝转载!