本文共 1270 字,大约阅读时间需要 4 分钟。
php连接访问Oracle是用过oci函数,以下是整理的文档
- yum install -y httpd php*
#rpm -ivh oracle-instantclient*(四个组件全部安装上)
此时会生成/usr/lib/oracle/10.2.0.4/client/lib/目录
/usr/lib/oracle/10.2.0.4/client/lib/
#./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client/lib/
成功后系统会提示你:oci8.so已经成功放入/usr/lib/php/modules/目录中
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);
-
- ?>
最后通过浏览器浏览页面
转载地址:http://tungx.baihongyu.com/