MySQL 在 Codeigniter 下,是否可以看到 mysql_error()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3234564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Under Codeigniter, is it possible to see mysql_error()?
提问by pbarney
I have an Codeigniter app (using version 2.1.0) that is writing a transaction to a mysql database. I'm fairly sure that I've got a foreign key constraint error occurring, but I can find no way to make CI tell me the specific error. mysql_error() comes back empty.
我有一个 Codeigniter 应用程序(使用版本 2.1.0)正在将事务写入 mysql 数据库。我很确定我发生了外键约束错误,但我找不到让 CI 告诉我特定错误的方法。mysql_error() 返回空。
Can anyone tell me how to get Codeigniter to tell me the mysql error message?
谁能告诉我如何让 Codeigniter 告诉我 mysql 错误消息?
回答by Bella
Yes, this is the mysql_error() wrapper.
是的,这是 mysql_error() 包装器。
$this->db->_error_message();
And the mysql_errno wrapper is:
mysql_errno 包装器是:
$this->db->_error_number();
回答by Amber
You may be able to use call_function
in the db class to access mysql_error
:
您可以call_function
在 db 类中使用来访问mysql_error
:
http://ellislab.com/codeigniter/user-guide/database/call_function.html
http://ellislab.com/codeigniter/user-guide/database/call_function.html
Of course, you could also just turn on the debug flag in the DB config, to tell CI to display db errors:
当然,你也可以在 DB config 中打开 debug 标志,告诉 CI 显示 db 错误:
http://ellislab.com/codeigniter/user-guide/database/configuration.html
http://ellislab.com/codeigniter/user-guide/database/configuration.html
db_debug - TRUE/FALSE (boolean) - Whether database errors should be displayed.
db_debug - TRUE/FALSE (boolean) - 是否应显示数据库错误。