php - 将错误存储在数据库中的错误函数

标签 php mysql database error-handling pdo

我有这个函数来处理我的错误
在 php 查询和类似的事情中

但我认为如果我可以将错误保存在数据库中然后将其显示在我的管理控制面板中,这样就没有人可以看到我网站上的错误

这是函数:

function er($str) {
global $db;
if (!$str) {
$errornum = $db->errorinfo();
echo $errornum[2];
die;
  }
}

在这里我试图做我说过我想做的事:

function er($str) {
global $db;
if (!$str) {
$errornum = $db->errorinfo();
$en = $errornum[2];
echo "".$en."";
$db->query("INSERT INTO `error` (`con`) VALUES ('$en')");
die;
  }
}
<小时/>
The Problem Is :   

that the query dosent do anything

The Reason Is :

i believe that the reason is that $en is empty ... so the insert wont do anything as it dosent have a name to insert it into the database , but $en isnt empty as when i echo it i dose output the error .. i fugure that out while i was trying to get it work i replaced $en with (Example) and it worked and (Example) was there in the database

Fix :

I'm not sure but i think if i can get it to paste the real value of the $en .. then it will be working :D

But i need you to help me to do it or point me to the right direction

最佳答案

嗯。

你必须摆脱什么:

  • 不死()
  • 没有错误回显到浏览器
  • 没有数据库日志记录

你真正需要做的事情:

这样,您将在 cpanel 中看到所有错误,并且不会向用户发送任何错误。

关于php - 将错误存储在数据库中的错误函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17591463/

相关文章:

php - PHP解析/语法错误;以及如何解决它们

javascript - CMS的Google Analytics API授权(单一授权)

php - 合并和 str_replace

mysql - Django 上的 SQL 缓存

mysql - Mac OS X El Capitan 上安装 MySQL 5.7 时出现错误

MySQL 查询 : ID not equal and with multiple LIKE operator not working

javascript - 单击提交按钮后jquery显示警报

php - Ajax 聊天系统每秒在控制台发送 XHR Finished Loading

连接到远程 MySQL 数据库的 Java 程序(运行 ssh 服务器)

android - 如何在 Android 中实现 RESTFUL 服务?