php串連訪問Oracle是用過oci函數,以下是整理的文檔1.安裝Apache和php包
- yum install -y httpd php*
2.下載Oracle組件oracle-instantclient-basic-10.2.0.4-1.i386.rpmoracle-instantclient-sqlplus-10.2.0.4-1.i386.rpmoracle-instantclient-devel-10.2.0.4-1.i386.rpmoracle-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.tgz5.編輯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.so7.重啟Apache服務service httpd restart8.使用phpinfo()函數查看
650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/1913063U7-0.jpg" />
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);
-
- ?>
最後通過瀏覽器瀏覽頁面
650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/19130C614-1.jpg" />
本文出自 “老徐的私房菜” 部落格,謝絕轉載!