php聯結訪Oracle是用過oci函數

來源:互聯網
上載者:User
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資料庫


  1. php
  2. $conn = oci_connect('scott', 'oracle', '192.168.12.133/orcl');
  3. if (!$conn) {
  4. $e = oci_error();
  5. print htmlentities($e['message']);
  6. exit;
  7. }
  8. $query = 'select ename,sal from scott.emp';
  9. $stid = oci_parse($conn, $query);
  10. if (!$stid) {
  11. $e = oci_error($conn);
  12. print htmlentities($e['message']);
  13. exit;
  14. }
  15. $r = oci_execute($stid, OCI_DEFAULT);
  16. if(!$r) {
  17. $e = oci_error($stid);
  18. echo htmlentities($e['message']);
  19. exit;
  20. }
  21. print '<table border="1">';
  22. while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
  23. print '<tr>';
  24. foreach($row as $item) {
  25. print '<td>'.($item?htmlentities($item):' ').'td>';
  26. }
  27. print 'tr>';
  28. }
  29. print 'table>';
  30. oci_close($conn);
  31. ?>

最後通過瀏覽器瀏覽頁面




  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.