我正在修改一个系统,当发现现有电子邮件,发现现有国民身份证(NIC)以及验证码失败时,我需要在注册失败时添加错误日志。要插入错误日志记录,将使用表z_error_log。我认为这需要在Vendor_cont.php文件的“其他”部分中完成。当前,如果使用现有电子邮件,这将提供错误信息。我需要将该错误日志发送到数据库。
这是代码,非常感谢您的帮助。提前致谢。
================ Vendor.php ============
public function register_vendor(){
//Function Body
}
======== Log_model.php =============
public function createErrorLog($user,$function,$error_data,$data){
$ip=$_SERVER['REMOTE_ADDR'];
$browser_os= $_SERVER['HTTP_USER_AGENT'];
$data= (array) $data_obj;
//print_r($data);
if (is_array($data)) {
$val = '(' . implode(',', array_keys($data)) . ')';
$val .= '=(' . implode(',', $data) . ')';
} else {
$val = $data;
}
$oStmt= $this->oDb->prepare('INSERT INTO z_error_log (`row_id`,`user`,`ip`,`page`,`function`,`data`,`browser_os`) VALUES (:row_id,:user,:ip,:page,:function,:data,:browser_os)');
$oStmt->bindParam(':row_id', $row_id, \PDO::PARAM_INT);
$oStmt->bindParam(':user', $user, \PDO::PARAM_INT);
$oStmt->bindParam(':ip', $ip, \PDO::PARAM_STR);
$oStmt->bindParam(':page', $page1, \PDO::PARAM_STR);
$oStmt->bindParam(':function', $page_url, \PDO::PARAM_STR);
$oStmt->bindParam(':data', $val, \PDO::PARAM_STR);
$oStmt->bindParam(':browser_os', $browser_os, \PDO::PARAM_STR);
$oStmt->execute();
return $this->oDb->lastInsertId();
}
最佳答案
您的代码中没有try catch块,但是您可以像这样使用它
public function register_vendor(){
try{
//Your logic
}catch(Exception $exception){
//Then in here you can get the error message and save it into db
echo $exception->getMessage();
echo $exception->getLine();
echo $exception->getCode();
}
}
关于php - 将注册失败的错误日志插入PHP中的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59658358/