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'; }