php串連oracle資料庫_PHP教程

來源:互聯網
上載者:User
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組件
#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()函數查看

9.編輯php代碼串連測試oracle資料庫

$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 '

















'; while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) { print ' '; foreach($row as $item) { print ' '; } print ' '; } print '
'.($item?htmlentities($item):' ').'
';

oci_close($conn);

?>
最後通過瀏覽器瀏覽頁面

本文出自 “不積跬步無以至千裡” 部落格,謝絕轉載!

http://www.bkjia.com/PHPjc/477919.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477919.htmlTechArticlephp串連訪問Oracle是用過oci函數,以下是整理的文檔 1.安裝Apache和php包 yum install -y httpd php* 2.下載Oracle組件 oracle-instantclient-basic-10.2.0.4-1.i386...

  • 聯繫我們

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