我正在尝试在代码下运行,但是我的try块中出现错误。有人可以帮我解决一下吗。 我创建了一个脚本,该脚本将日志文件上传到oracle数据库。我曾经有一个班级,我的职能很少。我用过try catch块,但是它抛出错误。不知道为什么。
<?php
class logAgent
{
const CONFIG_FILENAME = "data_config.ini";
private $_dbConn;
private $_config;
function __construct()
{
$this->_loadConfig();
$this->_dbConn = oci_connect($this->_config['db_usrnm'],
$this->_config['db_pwd'],
$this->_config['hostnm_sid']);
}
private function _loadConfig()
{
$path = dirname(__FILE__) . '/' . self::CONFIG_FILENAME;
$this->_config = parse_ini_file($path) ;
}
public function uploadLog(){
$d = new DateTime();
$yesterday = $d->sub(new DateInterval('P1D'))->format('Y.m.d');
$filename = "access.$yesterday.log";
if(file_exists($filename)){
$myfile = fopen($filename, "r");
while(!feof($myfile)) {
$content= fgets($myfile);
$carray=explode(',',$content);
list($IP_ADDRESS, $USER_IDENTIFIER, $USERID , $REQUEST_TIME , $CLIENT_REQUEST ,$RESPONSE_CODE ,$SIZEOFOBJECT, $COOKIES, $AUTHSCHEME, $AUTHMARKET, $X_REQUESTED_WITH, $ENV, $TANUSER)=$carray;
if (strlen(str_replace($this->_config['discardedextensions'], '', $CLIENT_REQUEST)) !== strlen($CLIENT_REQUEST)) {
// Found an image
continue;
}
$statement = 'INSERT INTO LOGS(IP_ADDRESS, USER_IDENTIFIER, USERID , REQUEST_TIME , CLIENT_REQUEST ,RESPONSE_CODE ,SIZEOFOBJECT, COOKIES, AUTHSCHEME, AUTHMARKET, X_REQUESTED_WITH, ENV, TANUSER)'.
'values(:IP_ADDRESS, :USER_IDENTIFIER, :USERID , :REQUEST_TIME , :CLIENT_REQUEST ,:RESPONSE_CODE ,:SIZEOFOBJECT, :COOKIES, :AUTHSCHEME, :AUTHMARKET, :X_REQUESTED_WITH, :ENV, :TANUSER)';
//Preparing an Oracle statement for execution
$compiled = oci_parse($this->_dbConn, $statement);
//binding values to named parameters
oci_bind_by_name($compiled, ':IP_ADDRESS', $IP_ADDRESS);
oci_bind_by_name($compiled, ':USER_IDENTIFIER', $USER_IDENTIFIER);
oci_bind_by_name($compiled,':USERID', $USERID);
oci_bind_by_name($compiled, ':REQUEST_TIME', $REQUEST_TIME);
oci_bind_by_name($compiled, ':CLIENT_REQUEST', $CLIENT_REQUEST);
oci_bind_by_name($compiled, ':RESPONSE_CODE', $RESPONSE_CODE);
oci_bind_by_name($compiled, ':SIZEOFOBJECT', $SIZEOFOBJECT);
oci_bind_by_name($compiled, ':COOKIES', $COOKIES);
oci_bind_by_name($compiled, ':AUTHSCHEME', $AUTHSCHEME);
oci_bind_by_name($compiled, ':AUTHMARKET', $AUTHMARKET);
oci_bind_by_name($compiled, ':X_REQUESTED_WITH', $X_REQUESTED_WITH);
oci_bind_by_name($compiled, ':ENV', $ENV);
oci_bind_by_name($compiled, ':TANUSER', $TANUSER);
//Executing statement
oci_execute($compiled, OCI_COMMIT_ON_SUCCESS);
}
//Alert if the file has been uploaded
$message="File Uploaded";
echo "<script type='text/javascript'>alert(\"$message\");</script>";
//closing the file
fclose($myfile);
}
}
function sendEmail(){
//$to = "swapnil.sneha@onelife.eu.com";
$subject = "File Not Uploaded";
$message = "Exception Found";
mail($this->_config['recipients'], $subject, $message);
}
try {
$logAgent = new logAgent();
$logAgent->uploadLog();
}
catch (Exception $e) {
$logAgent->sendEmail();
}
}
?>
答案 0 :(得分:0)
您错过了类定义的结尾},或者它在错误的位置,从底部开始将其放在该类的最后定义的方法之后
答案 1 :(得分:0)
我发现了我的错误。我试图使用try catch,在其中创建类的对象并在类内调用类的函数。我在尝试捕捉之前关闭了班级,现在一切正常。