当前位置: 首页 > 后端技术 > PHP

PHP7连接Oracle环境构建测试代码

时间:2023-03-29 13:39:44 PHP

1.需要Java库环境:1)instantclient-basic-linux和instantclient-sdk-linux可以解压到同一个目录下。//特别注意百度搜索找到的第一个Oracle中文官方地址是一个坑,并且无法完成下载https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html2)编译安装oci8,可以直接通过pecl安装:oci8官方安装guidepeclinstalloci8-2.2.0//注意php7需要的版本是2.2,php8需要的版本是3.0//安装过程中需要进入instantclient目录,输入格式如下:instantclient,/path/to/instantclient_19_8,19.8//安装完成后记得在php中添加oci8.so。inifileextension=oci8.so3)Installpdo_ocisupport//这个需要从源码安装,根据你本地安装的php版本,去php官方下载对应的源码([github](https://github.com/php/php-src))cdext/pdo_oci./configure--with-pdo-oci=instantclient,/data1/oracle/instantclient_19_8,19.8//这个过程可能会遇到缺少一些库,安装即可对应库扩展=pdo-oci.so4)PDO连接测试代码getMessage());}$sql="SELECT*FROMtest";$ret=$conn->query($sql);//打印错误print_r($conn->errorInfo());5)连接Oracle时出现中文乱码//连接时添加指定的字符集即可newPDO($db.$tns.';charset=UTF8',$db_username,$db_password);