php连接oracle数据库的方法
1.在php.ini中打开extension=php_oci8扩展,重启服务。
2.将php/ext目录下的php_oci8.dll文件拷贝到system32目录下
3.安装 Oracle9i客户端精简版 后重启电脑
配置:
$config = array ( 'dbconfig' => array ( 'db_host_name' => '192.168.2.197/orcl', 'db_user_name' => 'zbkf', 'db_password' => 'zbkf', ), );
查询:
//返回值 $arr_result = array(); $arr_result['result'] = 'false'; //true false 为黑名单 $arr_result['callerid'] = $callerid; //取数据库参数 $db_host_name=$config['dbconfig']['db_host_name']; //'localhost/ORCL'' $db_user_name=$config['dbconfig']['db_user_name'];//'asgr' $db_pwd=$config['dbconfig']['db_password']; //'asgr' //连接Oracle $conn = oci_connect($db_user_name,$db_pwd,$db_host_name);//oci_connect('asgr','asgr','localhost/ORCL'); if (!$conn) { $e = oci_error(); //print htmlentities($e['message']); //WriteLog("连接Oracle时出错,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") ".htmlentities($e['message'])); $arr_result['result'] = 'false'; echo json_encode($arr_result); //默认为不是黑名单 return; } else { //echo("连接成功!"); //$select = 'SELECT BL_TEL FROM CC_BLACKLIST'; // 查询语句 $select = "Select count(BL_Tel) from CC_BlackList where BL_Tel like '%" . $callerid . "%' and BL_SFQY='0' "; //WriteLog($select); $result_rows = oci_parse($conn, $select); // 配置SQL语句,执行SQL $row_count = oci_execute($result_rows, OCI_DEFAULT); // 行数 OCI_DEFAULT表示不要自动commit //echo($row_count); if(!$row_count) { //没有行 $e = oci_error($result_rows); //echo htmlentities($e['message']); //WriteLog("查询时出错或没有行!,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") ". $select." ".htmlentities($e['message'])); $arr_result['result'] = 'false'; echo json_encode($arr_result); //默认为不是黑名单 } /* //取每行每列值 while($row = oci_fetch_array($result_rows, OCI_RETURN_NULLS)) { if($row[0]==$callerid){ $arr_result['result']='true'; echo json_encode($arr_result); //是黑名单 exit; } } */ $count=0; while($row = oci_fetch_array($result_rows, OCI_RETURN_NULLS)) { $count=$row[0]; break; } //WriteLog($count); if($count>=1){ $arr_result['result']='true'; } else { $arr_result['result']='false'; } echo json_encode($arr_result); //默认为不是黑名单 }
插入:
//连接Oracle $conn = oci_connect($db_user_name,$db_pwd,$db_host_name);//oci_connect('asgr','asgr','localhost/ORCL'); if (!$conn) { $e = oci_error(); //print htmlentities($e['message']); WriteLog("连接Oracle时出错,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") ".htmlentities($e['message'])); $arr_result['result'] = 'false'; echo json_encode($arr_result); //默认为不是黑名单 return; } else { //echo("连接成功!"); $sql = "insert into CC_LEAVEMESSAGE (ID,MESSAGEID,CALLINGNBR,LEAVEMESSAGETIME,FILENAME) values (sys_guid(),'" . $SessionId . "','" . $CallerId . "',sysdate,'" . $RecordFile . "')"; //WriteLog($sql); $stid = oci_parse($conn, $sql); // 编译SQL语句,准备执行 $r = oci_execute($stid); // 执行SQL oci_free_statement($stid); oci_close($con); //关闭连接 //WriteLog($r); if(!$r) { $e = oci_error($sql); WriteLog("留言写入Oracle时出错,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") " .$sql . ' ' .htmlentities($e['message'])); $arr_result['result']='false'; } else{ $arr_result['result']='true'; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2010-08-17 C# 实现系统报警
2010-08-17 C# 时间间隔与时间相加