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資料庫
- 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);
-
- ?>
最後通過瀏覽器瀏覽頁面