本文中仔細講述了在Linux環境下用PHP4串連Oracle8i的具體方法。
1.下載並安裝 Oracle 8i for linux。完整安裝,不要只安裝用戶端。
2. 下載PHP3或PHP4源碼。
3. 配置PHP的安裝參數:
for php 4:./configure with-apxs=/usr/sbin/apxsprefix=/usrwith-gdenable-versioningwith-mysql=/usrwith-oracle=/usr/local/oracle/8i/u01/app/oracle/product/8.1.5with-oci8=/usr/local/oracle/8i/u01/app/oracle/product/8.1.5with-zlibwith-dbasewith-fileprowith-config-file-path=/etc/httpd/confwith-fdftk=noenable-debug=noenable-magic-quotesenable-debuggerenable-bcmathenable-track-varsenable-safe-modewith-exec-dir=/usr/binwith-system-regexno-createno-recursion |
with-oracle 選項讓php可以通過ORA_函數訪問 Oracle 7.x 或8.x。
with-oci8 選項讓php可以使用更多更好的oci8函數。
4. make。
5. make install。
6. cp ./php.ini-dist /wherever/your/conf/files/are/php.ini將php.ini拷貝到適當的位置。
7. 修改httpd.conf,修改如LoadModule php4_module lib/apache/libphp4.so,改為:LoadModule php4_module /usr/lib/apache/libphp4.so。
8. 重新啟動APACHE。
9. 測試PHP4的安裝是否成功。建立一個test.php3內容為:在瀏覽器中訪問它,看是否有ORACLE和ORACLE8的資訊。如果有的話,那麼就成功了。
10. 現在開始使用Oracle的函數:
<?// 設定ORACLE環境變數putenv("ORACLE_SID=PROD");putenv("ORACLE_HOME=/usr/local/oracle/8i/u01/app/oracle/product/8.1.5");// 建立串連// 修改現在的user_id,password,db以適應你的配置if($conn = OCILogon("user_id","password","db")){// 取得資料庫的資訊printf("%s</P>", OCIServerVersion($conn));}else{printf("Conncetion Failed");}?> |
這段程式會顯示出你所串連到的Oracle的一些資訊。
12. 其它:
如果你需要串連到遠端ORACLE伺服器,你就還需要設定你的sqlnet.ora 和 tnsnames.ora 來指定遠端資料庫的位置。向資料庫管理員要求,拷貝一些檔案放到$ORACLE_HOME/network/admin/ 目錄下。