Home >Backend Development >PHP Problem >How to use php to connect to remote oracle in win7
I believe everyone knows Oracle, but not everyone knows how to use PHP to connect to a remote Oracle. Today I will take you through how to use PHP to connect to a remote Oracle. Friends in need can refer to it.
<?php /* 先下载oracle客户端 下载地址 http://www.oracle.com/technetwork/topics/winx64soft-089540.html 下载如下三个版本 instantclient-basic-win64-10.2.0.5.zip instantclient-sqlplus-win64-10.2.0.5.zip instantclient-odbc-win64-10.2.0.5.zip 另下载php Oracle驱动,下载地址 https://windows.php.net/downloads/pecl/releases/oci8/2.0.10/ 这里版本是 php_oci8-2.0.10-5.5-ts-vc11-x64.zip 将其中内容全部解压缩到php编译文件目录下的 ext 文件夹里 这里是 D:\ApacheServer\php\ext 将三个压缩包解压缩到一个默认文件夹 instantclient_10_2 下 这里instantclient_10_2 放在了 Navicat Premium 安装目录下,位置为 D:\ApacheServer\Navicat Premium\instantclient_10_2 修改环境变量 全部在系统变量中 修改如下 新增 变量名 NLS_LANG 变量值 SIMPLIFIED CHINESE_CHINA.ZHS16GBK 变量名 ORACLE_HOME 变量值 D:\ApacheServer\Navicat Premium\instantclient_10_2 变量名 TNS_ADMIN 变量值 D:\ApacheServer\Navicat Premium\instantclient_10_2 修改 变量名 Path 结尾处新增 ;D:\ApacheServer\Navicat Premium\instantclient_10_2 注意和之前值之间有个 ; instantclient_10_2 目录下新建 TNSNAME.ORA,这里是D:\ApacheServer\Navicat Premium\instantclient_10_2\TNSNAME.ORA 内容如下 ================================以下TNSNAME.ORA内容============================== SHTSDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 45.97.194.92)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = SHTSDB) ) ) EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) ================================以上TNSNAME.ORA内容============================== SHTSDB 是Oracle实例名(库名,SID名),服务器IP 45.97.194.92,端口号1521 启动命令行 d: cd D:\ApacheServer\Navicat Premium\instantclient_10_2 odbc_install.exe 最后重启电脑 输入如下代码测试即可 新建index.php页面,输入如下内容 */ phpinfo();exit; $db_server = "45.97.194.92"; $db_user = "YIMAI"; $db_pass = "YIMAI"; $db_sid = "SHTSDB"; $dbconn=OCILogon($db_user,$db_pass,"(DEscriptION=(ADDRESS=(PROTOCOL=TCP)(HOST=45.97.194.92)(PORT= 1521))(CONNECT_DATA =(SID=$db_sid)))"); if($dbconn!=false) { echo "连接"; echo "DB服务器:".$db_server; echo "用户:".$db_user; echo "口令:".$db_pass; echo "SID:".$db_sid; echo "成功\n"; if(OCILogOff($dbconn)==true) { echo "关闭连接成功!"; } } else { echo "连接失败"; } ?>
Recommended learning: php video tutorial
The above is the detailed content of How to use php to connect to remote oracle in win7. For more information, please follow other related articles on the PHP Chinese website!