gpt4 book ai didi

php - 需要帮助触发数据库错误

转载 作者:行者123 更新时间:2023-11-29 03:30:55 25 4
gpt4 key购买 nike

我正在使用 CodeIgniter $db->insert 函数来执行插入。但我试图弄清楚如何通过查询触发错误以查看系统是否记录错误消息。

我试过拼错表名,但那行不通..它只会在页面上显示一条错误消息。

关于如何执行假错误的任何想法?下面是我的代码..

非常感谢任何帮助!

 public function newMsgTemplate($template_name, $body){


try {

$this->db->insert("message_template", ['template_name' => $template_name, 'body' => $body]);
trigger_error("error");
} catch (Exception $e){

log_message("error", "There was an error when trying to preform the query ");

}

最佳答案

尝试自己抛出异常。

public function newMsgTemplate($template_name, $body){
try {
$this->db->insert("message_template", ['template_name' => $template_name, 'body' => $body]);
trigger_error("error");
throw new MyException('foo!');
} catch (Exception $e){

log_message("error", "There was an error when trying to preform the query ");

}

Source

关于php - 需要帮助触发数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30810866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com