我有这个函数来处理我的错误
在 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
最佳答案
嗯。
你必须摆脱什么:
- 不死()
- 没有错误回显到浏览器
- 没有数据库日志记录
你真正需要做的事情:
为 PHP 设置正确的错误报告。在实时服务器上它必须是
error_reporting(E_ALL); ini_set('display_errors',0); ini_set('log_errors',1);
让你的 PDO 抛出异常,如下所述:PDO query fails but I can't see any errors. How to get an error message from PDO?
这样,您将在 cpanel 中看到所有错误,并且不会向用户发送任何错误。
关于php - 将错误存储在数据库中的错误函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17591463/