本篇文章给大家分享的是有关php连接不上orcle的问题,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
在php.ini中打开extension=php_oci8扩展,重启服务。
将php/ext目录下的php_oci8.dll文件拷贝到system32目录下,安装 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); //默认为不是黑名单
}
以上就是php连接不上orcle的问题,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。