centos的php环境搭建好后怎么使用(centos7PHP7.2连接oracle)
centos的php环境搭建好后怎么使用(centos7PHP7.2连接oracle)安装成功rpm -qa | grep oracle执行命令rpm -ivh oracle-instantclient-basic-10.2.0.5-1.x86_64.rpmrpm -ivh oracle-instantclient-devel-10.2.0.5-1.x86_64.rpmrpm -ivh oracle-instantclient-sqlplus-10.2.0.5-1.x86_64.rpm执行以下命令检查安装是否完毕:
PHP支持的数据库有MySQL、ORACLE、Sql Server、MongoDB和SQLite等等,你是不是只会用mysql。因项目需要,对oracle进行操作!网上各种方法,杂乱无章,顾亲自整理一份简单,易操作的方法,实现php 操作oracle。
安装Oracle Instant Client在Oracle官网下载对应RPM包,这里以Oracle10.2为例,其他版本也可以参考,oracle官网地址:https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
我用的安装包,可以共享给大家
安装包
执行命令
rpm -ivh oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm
rpm -ivh oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm
rpm -ivh oracle-instantclient-sqlplus-10.2.0.5-1.x86_64.rpm
执行以下命令检查安装是否完毕:
rpm -qa | grep oracle
安装成功
二、修改系统配置创建32位软连接
ln -s /usr/lib/oracle/10.2.0.5/client64 /usr/lib/oracle/10.2.0.5/client
ln -s /usr/include/oracle/10.2.0.5/client64 /usr/include/oracle/10.2.0.5/client
三、添加环境变量编辑/etc/profile,在最下面添加以下几行:
export ORACLE_HOME=/usr/lib/oracle/10.2.0.5/client64
export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.5/client64:$LD_LIBRARY_PATH
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
使环境变量立即生效
source /etc/profile
四、编译PHP扩展1.查看PHP版本相关信息tar -xvzf oci8-2.0.5.tgz
cd oci8-2.0.5.tgz
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-oci8=instantclient /usr/lib/oracle/10.2.0.5/client64/lib
make && make install
3.修改php.ini,启用扩展编辑/usr/local/php/etc/php.ini文件,并加入如下配置:
extension=oci8
4.检查安装是否正确php --ri oci8
private $config = [
'connection_string' => '10.20.2.13/orcl'
"username"=>"zfsoft_zjk"
"password"=> "zjk_GMUXS333MS"
];
$conn = oci_connect($this->config['username'] $this->config['password'] $this->config['connection_string']);
if(!$conn){
$e = oci_error();
print htmlentities($e['message']);
exit;
}else{
echo "连接oracle成功!";
}
$sql = "select * from jw_user.md_subject";
$ora_test = oci_parse($conn $sql); //编译sql语句
oci_execute($ora_test OCI_DEFAULT); //执行
while($row = oci_fetch_array($ora_test OCI_RETURN_NULLS)){
print_r($row);
}
到此即可打印出每一条数据!!
下一篇:
php 连接 Sql Server