CodeIgniter - 继续SQL错误? [英] CodeIgniter - continue on SQL error?
问题描述
基本上,我有一个表,其中有几列标记为唯一。我有一个脚本,使用这样的命令将一堆值转储到表中:
Basically I have a table with a couple of columns marked Unique. I have a script that dumps a bunch of values into the table with a command like this:
$this->db->query("INSERT INTO `table` (`col1`, `col2`, `col3`) VALUES (`val1`, `val2`, `val3`)");
经常,我的脚本会尝试插入一行,这会违反其中一列的唯一性。但是,不是让脚本中止数据库错误,我希望它继续,可能输出一个小消息。基本上我正在寻找等于
Every so often my script will try to insert a row which would violate the uniqueness of one of the columns. However, instead of causing the script to abort with a database error, I'd like it to continue, possible outputting a little message. Basically I'm looking for the codeigniter equivalent of
mysql_query("INSERT blah blah blah") or print("fail");
感谢!
Mala
Thanks!
Mala
推荐答案
是啊,花了我一会儿,惹恼了我的地狱:
Yeah, took me a while too and annoyed the hell out of me:
$db['default']['db_debug'] = FALSE;
...在 config / database.php
- 禁用错误页面。
... in config/database.php
- disables the error page.
查询运行后,使用此命令检查错误:
After a query ran, use this to check for an error:
if (!empty($this->db->_error_message())) {
echo "FAIL";
}
这篇关于CodeIgniter - 继续SQL错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!