首頁  >  文章  >  後端開發  >  php7.2怎麼連接oracle資料庫? OCI8擴充的安裝

php7.2怎麼連接oracle資料庫? OCI8擴充的安裝

青灯夜游
青灯夜游轉載
2022-07-22 14:59:583351瀏覽

php7.2怎麼連接oracle資料庫?以下這篇文章跟大家介紹一下php7.2安裝OCI8擴充支援oracle資料庫的方法,希望對大家有幫助!

php7.2怎麼連接oracle資料庫? OCI8擴充的安裝

做專案的時候,遠端的oracle資料庫為我們提供一張中間表,我這邊業務中的一些資料是需要到oracle資料庫中的這張中間表去查詢的。

PHP連接oracle資料庫。需要用到OCI8的擴充。說來慚愧,工作這麼多年,還沒有正經的使用過oracle資料庫。

mysql資料庫的語法跟oracle資料庫的語法是不一樣的,別跟我似的上來就用mysql的語法來操作oracle資料庫…有點丟臉了…

今天我們大概記錄一下OCI8擴充的安裝過程。

一:下載檔案

1 :oracle官網下載網址:

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

#下載檔案(看準了檔案名稱):

oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm

oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm复制代码

2 :PHP官網下載位址:

https://www.php.net/manual/zh/oci8.installation.php

PHP-OCI8外掛程式

下載指令:

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

建議將以上三個檔案放入/opt目錄下,當然,具體放哪是你的自由。能找到就行。

二:安裝

1 :安裝oracle外掛程式

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

可能會報錯誤:

ImportError: libaio.so.1: cannot open shared object file: No such file or directory”

#錯誤原因上邊已經給出,缺少libiao插件,解決方法:

yum install libaio

2 :安裝OCI8插件

(1):解壓縮tar套件:

tar -zxf oci8-2.2.0.tgz

(2):進入解壓縮目錄

cd oci8-2.2.0

(3):執行指令:

phpize

運行的時候可能會出現錯誤:Can't find PHP headers in /usr/include/php The php-devel package is required for use

解決方案

 yum install php72w-devel #注意一下,这条命令取决你安装的PHP版本,我这个命令并不适用所有人

(4):使用$ORACLE_HOME或Instant Client設定軟體包

./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib</version>

./configure -with-oci8=shared,$ORACLE_HOME

(5):執行編譯安裝:

make install

#這裡可能會報錯:

make: ** * No rule to make target build', needed by default'. Stop.

解決方案:

##1:安裝如下設定:
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

2: 重新 configure
./configure

3: 編譯
make && make install

(6):設定php.ini

我們在PHP的設定檔php.ini加上

extension=oci8.so
重啟PHP

systemctl restart php-fpm
重啟web伺服器(nginx、apache等)。

systemctl restart nginx
查看

PHPinfo();如下圖所示:

php7.2怎麼連接oracle資料庫? OCI8擴充的安裝

然後,你就可以在你的PHP框架中配置多個資料庫連結了。

#推薦學習:《

PHP影片教學

以上是php7.2怎麼連接oracle資料庫? OCI8擴充的安裝的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:juejin.cn。如有侵權,請聯絡admin@php.cn刪除