如果发生错误,如何使用以下脚本将事件插入到数据库中


If an error occurs, how do i insert the incident in to the db using the following script?

如果发生重复id错误,我想将其记录到数据库中。我正在使用下面的这个片段,我如何使它在数据库中插入错误信息的空间?

代码:

 if ( $postedid === $storedid ) {
 require("error.php");
 die("");
 }else{ 
 echo("");
 }

您必须在关闭脚本之前插入它(die())。您插入一个db查询来记录错误。

您只需将MySQL查询传递给die();函数。

使用

可以得到错误

mysqli.errno.php和mysqli.error.php

DB QUERY -

INSERT INTO error (type, page) VALUES ('{mysqli_error($dbc)}','{$_SERVER['PHP_SELF']}')
<?php
if ( $postedid === $storedid ) {
 require("error.php");
    $type = mysqli_error($dbc); //Where $dbc is your connection resource. 
    $file = $_SERVER['PHP_SELF'];
      $q = "INSERT INTO error (type, page) VALUES ('{$type}','{$file}')";
 die( $r = mysqli_query ($dbc, $q) );}
 else{ 
    echo("");
 }
?>