Oracle 10g Instant Client

來源:互聯網
上載者:User

在Linux上啟用PHP OCI8擴充
要在Linux上添加Oracle串連,需要重新編譯PHP。
1.下載並安裝Apache

  1. cd apache_1.3.31  
  2. ./configure --prefix=/usr/local/apache \  
  3.       --enable-module=so \  
  4.       --enable-shared=max \  
  5.       --enable-module=most  
  6. make  
  7. make install  
--enable-module=so so模組用來提供DSO支援的apachehe核心模組
--enable-shared=max 除了so以外的所有標準模組都編譯成DSO模組(so不能被編譯成DSO)
--enable-module=most 將一些常用的,不在預設常用模組中的模組編譯進Apache
2.下載並解壓Instant Client
instantclient-odbc-linux32、instantclient-jdbc-linux32根據自己需要是否解壓。
  1. unzip instantclient-basic-linux32-10.2.0.3-20061115.zip -d /tmp  
  2. unzip instantclient-sdk-linux32-10.2.0.3-20061115.zip -d /tmp  
  3. unzip instantclient-sqlplus-linux32-10.2.0.3-20061115.zip -d /tmp  
  4. mv instantclient_10_2 /usr/local  
  5. export LD_LIBRARY_PATH=/usr/local/instantclient_10_2  
  6. cd $LD_LIBRARY_PATH  
  7. ln -s libclntsh.so.10.1 libclntsh.so  
  8. ln -s libocci.so.10.1 libocci.so 實際安裝時,並未建立此串連  
  9. ln -s libsqora.so.10.1 libsqora.so 實際安裝時,並未建立此串連  
3.下載並安裝php
  1. tar -xvzf php-5.2.3.tar.gz  
  2. ./configure --prefix=/usr/local/php \  
  3.       --with-apxs=/usr/local/apache/bin/apxs \  
  4.       --with-oci8=instantclient,$LD_LIBRARY_PATH \  
  5.       --enable-sigchild  
  6. make  
  7. make install  
  8. cp php.ini-dist /usr/local/lib/php.ini  
4.編輯/usr/local/apache/conf/httpd.conf 並添加:
  1. AddType application/x-httpd-php .php  
  2. AddType application/x-httpd-php-source .phps  
  3. ServerName 127.0.0.1  
  4. DocumentRoot "/var/www"  
  5. <Directory "/var/www">  
  6. DirectoryIndex index.html index.php  
5.測試OCI8支援
<?php phpinfo(); ?>
瀏覽器頁面應包含一個顯示“OCI8 Support enabled”的“oci8”部分。
6.測試連接Oracle
(A)sqlplus
  1. export LD_LIBRARY_PATH=/usr/local/instantclient_10_2  
  2. export TNS_ADMIN=/usr/local/instantclient_10_2  
  3. sqlnet.ora檔案內容如下:  
  4. SQLNET.AUTHENTICATION_SERVICES= (NTS)  
  5. NAMES.DIRECTORY_PATH= (TNSNAMES)  
  6. tnsnames.ora檔案內容如下:  
  7. test =  
  8.  (DESCRIPTION =  
  9.   (ADDRESS_LIST =  
  10.    (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))  
  11.   )  
  12.   (CONNECT_DATA =  
  13.    (SID = test)  
  14.   )  
  15.  )  
  16. ./sqlplus user/passwd@test  
(B)php
  1. vi /etc/rc.local  
  2. export LD_LIBRARY_PATH=/usr/local/instantclient_10_2  
  3. export TNS_ADMIN=/usr/local/instantclient_10_2  
  4. export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"  
  5. /usr/local/apache/bin/apachectl start  
  6. vi /var/www/testoci.php  
  7. <?php  
  8.  $conn = ocilogon("user", "passwd", "test");  
  9.  $query = 'select table_name from user_tables';  
  10.  $stid = ociparse($conn, $query);  
  11.  ociexecute($stid, OCI_DEFAULT);  
  12.  while($succ = ocifetchinto($stid, $row))  
  13.  {  
  14.   foreach($row as $item) {echo $item." ";}  
  15.   echo "<br>\n";  
  16.  }  
  17.  ocilogoff($conn);  
  18. ?>  
在FC3下通過。
在Windows上啟用PHP OCI8擴充
1.從OTN的Instant Client頁面下載用於Windows的Instant Client Basic程式包。
2.建立一個子目錄(例如,c:\instantclient10_1),然後從壓縮檔中複製以下庫:
 oraociei10.dll、orannzsbb10.dll、oci.dll
要使用PHP老版本的“oracle”擴充(在php.ini中使用“extension=php_oracle.dll”啟用),則複製ociw32.dll而非 oci.dll。
3.將c:\instantclient10_1添加到PATH中(位於其他Oracle目錄之前)。
 如果使用了tnsnames.ora檔案定義Oracle Net服務名稱,則將tnsnames.ora複製到c:\instantclient10_1,並將使用者環境變數TNS_ADMIN設定為c:\instantclient10_1。也可以在使用者環境變數LOCAL中定義預設的服務名稱。
 設定必要的Oracle全球化語言環境變數,如NLS_LANG。如果沒有設定,則使用預設的本地環境。有關更多詳細資料,請參見Oracle PHP應用程式全球化概述。
 無需設定不必要的Oracle變數,如ORACLE_HOME和ORACLE_SID。
4.編輯php.ini,並不要將OCI8擴充設為注釋:
 extension=php_oci8.dll
 將extension_dir指令設定為完整的PHP擴充DLL路徑。在PHP 4中,DLL位於PHP軟體的“extensions”子目錄中。在PHP 5中,它們位於“ext”中。
5.重新啟動Apache。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.