Cakephp 1.2.6 和 Postgresql 8
我在外壳上运行蛋糕。我使用了 save()。Postgresql有一些错误,我想将该错误保留在另一个数据库中。谁知道 Cakephp 或 Postgresql 中的命令可以将该错误保留为字符串?
example:
if($this->Model->save($data)) {
}
else {
/// command??
}
谢谢普雷斯利迪亚斯
尝试和捕捉对我不起作用。现在,我使用了这种方法:
$this->getDataSrouce()->error;
用于从数据库获取最后一个错误。
从 : http://www.sanisoft.com/blog/2011/07/05/how-to-track-sql-errors-in-cakephp-on-production-site/
如果你想捕获exception
然后保存在数据库中,那么你可以使用像这样薄
try {
if($this->Model->save($data)){
//do somthing
}
//now the exception occured.. so catch it
}catch (Exception $ex){
// this message is "ERROR: ". $ex->getMessage()
//save the message here to the other database where the message is $ex->getMessage()
}
与堆栈溢出相比还有 cakephp-exception 和 cakephp-throw-exceptions