当前位置:Gxlcms > PHP教程 > php为什么连接不上orcle

php为什么连接不上orcle

时间:2021-07-01 10:21:17 帮助过:26人阅读

在php.ini中打开extension=php_oci8扩展,重启服务。

将php/ext目录下的php_oci8.dll文件拷贝到system32目录下,安装 Oracle9i客户端精简版 后重启电脑 (推荐学习:PHP视频教程)

配置:

  1. $config = array (
  2. 'dbconfig' =>
  3. array (
  4. 'db_host_name' => '192.168.2.197/orcl',
  5. 'db_user_name' => 'zbkf',
  6. 'db_password' => 'zbkf',
  7. ),
  8. );

查询:

  1. //返回值
  2. $arr_result = array();
  3. $arr_result['result'] = 'false'; //true false 为黑名单
  4. $arr_result['callerid'] = $callerid;
  5. //取数据库参数
  6. $db_host_name=$config['dbconfig']['db_host_name']; //'localhost/ORCL''
  7. $db_user_name=$config['dbconfig']['db_user_name'];//'asgr'
  8. $db_pwd=$config['dbconfig']['db_password']; //'asgr'
  9. //连接Oracle
  10. $conn = oci_connect($db_user_name,$db_pwd,$db_host_name);//oci_connect('asgr','asgr','localhost/ORCL');
  11. if (!$conn) {
  12. $e = oci_error();
  13. //print htmlentities($e['message']);
  14. //WriteLog("连接Oracle时出错,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") ".htmlentities($e['message']));
  15. $arr_result['result'] = 'false';
  16. echo json_encode($arr_result); //默认为不是黑名单
  17. return;
  18. }
  19. else {
  20. //echo("连接成功!");
  21. //$select = 'SELECT BL_TEL FROM CC_BLACKLIST'; // 查询语句
  22. $select = "Select count(BL_Tel) from CC_BlackList where BL_Tel like '%" . $callerid . "%' and BL_SFQY='0' ";
  23. //WriteLog($select);
  24. $result_rows = oci_parse($conn, $select); // 配置SQL语句,执行SQL
  25. $row_count = oci_execute($result_rows, OCI_DEFAULT); // 行数 OCI_DEFAULT表示不要自动commit
  26. //echo($row_count);
  27. if(!$row_count) { //没有行
  28. $e = oci_error($result_rows);
  29. //echo htmlentities($e['message']);
  30. //WriteLog("查询时出错或没有行!,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") ". $select." ".htmlentities($e['message']));
  31. $arr_result['result'] = 'false';
  32. echo json_encode($arr_result); //默认为不是黑名单
  33. }
  34. /*
  35. //取每行每列值
  36. while($row = oci_fetch_array($result_rows, OCI_RETURN_NULLS)) {
  37. if($row[0]==$callerid){
  38. $arr_result['result']='true';
  39. echo json_encode($arr_result); //是黑名单
  40. exit;
  41. }
  42. }
  43. */
  44. $count=0;
  45. while($row = oci_fetch_array($result_rows, OCI_RETURN_NULLS)) {
  46. $count=$row[0];
  47. break;
  48. }
  49. //WriteLog($count);
  50. if($count>=1){
  51. $arr_result['result']='true';
  52. }
  53. else {
  54. $arr_result['result']='false';
  55. }
  56. echo json_encode($arr_result); //默认为不是黑名单
  57. }

以上就是php为什么连接不上orcle的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行