linux系統下php oracle擴充OCI8的安裝與配置

來源:互聯網
上載者:User

標籤:php oracle linux oci8

linux系統下php oracle擴充OCI8的安裝與配置

實現PHP程式訪問oracle DB
時間:2014.09.02
寫劉群英(qunyingliu)

  • 環境描述:apache版本,PHP版本,oracle DB版本,linux發行版本

  • RPM包安裝oracle-instantclient用戶端

  • 源碼編譯安裝oci8擴充

  • 系統內容與php配置修改:ld.so.conf.d目錄設定檔與php.ini中擴充欄位資訊修改

  • 重啟apache使修改生效

  • 測試連結代碼,確認配置成功

  1. 環境描述:

  • 本地系統:centos linux 6.4 x64

  • apache 2.2.22:/usr/local/apache2

  • PHP 5.4 : /usr/local/php

  • oracle DB 11.2.0.4

RPM包安裝本地oracle client:

從[oracle Instant Client 官網 下載以下RPM包:

http://www.oracle.com/technetwork/cn/topics/linuxx86-64soft-092277.html

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm 

oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm 

使用以下命令進行安裝:

rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm 

rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm


源碼編譯安裝oci8擴充下載:

wget http://pecl.php.net/get/oci8-1.4.10.tgz

解壓:tar -zxvf oci8-1.4.10.tgz

安裝:

cd oci8-1.4.10/usr/local/php/bin/phpize CFLAGS="-I/usr/lib/oracle/11.2.0.4.0/client64/" CXXFLAGS="-I/usr/lib/oracle/11.2.0.4.0/client64/"

./configure --with-php-config=/usr/local/php/bin/php-config --with-oci8=instantclient,/usr/lib/oracle/11.2.0.4.0/client64/lib/

make

make instal

lphp路徑和oracle client的路徑需根據實際情況進行修改。


如果系統中存在pecl程式,可通過以下命令來安裝oci8擴充:

pecl install oci8


系統內容與php配置修改修改系統配置:

echo    "/usr/lib/oracle/11.2.0.4.0/client64//lib/"

>/etc/ld.so.conf.d/oracle_client.conf/sbin/ldconfig


修改php.ini設定檔:

extension_dir = "/usr/local/php5/lib/ext"

extension = "oci8.so"

oci8.privileged_connect = on


重啟apache使修改生效


/usr/local/apache2/bin/apachectl restart


測試連結代碼,確認配置成功

<?php

$conn = oci_connect(‘qunyingliu‘, ‘testqunyingliu‘, ‘oracle.test.localhost/orcl‘);
//需要根據實際配置資訊進行修改

$stid = oci_parse($conn, ‘select table_name from user_tables‘);
//資料庫動作陳述式可根據實際需求進行修改
oci_execute($stid);

echo "<table>\n";
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo "

\n";
foreach ($row as $item) {
echo "<td>".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")."\n";
}
echo "\n";
}
echo "</table>\n";

?>

相關參考:
http://php.net/manual/zh/function.oci-connect.php
http://php.net/manual/zh/book.oci8.php
http://pecl.php.net/get/oci8-1.4.10.tgz
http://pecl.php.net/package-changelog.php?package=oci8
http://www.oracle.com/technetwork/cn/topics/linuxx86-64soft-092277.html


本文出自 “營運者說:從菜鳥到老鳥” 部落格,請務必保留此出處http://liuqunying.blog.51cto.com/3984207/1548023

linux系統下php oracle擴充OCI8的安裝與配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.