Home > Backend Development > PHP Problem > Why can't php connect to orcle?

Why can't php connect to orcle?

(*-*)浩
Release: 2023-02-27 12:58:01
Original
2938 people have browsed it

Why can't php connect to orcle?

Open the extension=php_oci8 extension in php.ini and restart the service.

Copy the php_oci8.dll file in the php/ext directory to the system32 directory, install the Oracle9i client streamlined version and restart the computer (recommended learning : PHP video tutorial)

Configuration:

$config = array (

    'dbconfig' => 
          array (
            'db_host_name' => '192.168.2.197/orcl',
            'db_user_name' => 'zbkf',
            'db_password' => 'zbkf',
             
          ),
);
Copy after login

Query:

//返回值  
    $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);  //默认为不是黑名单
    }
Copy after login

The above is the detailed content of Why can't php connect to orcle?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template