我正在以API扩展的形式开发MediaWiki 1.16的扩展。我正在使用数据库访问函数wfGetDB
,但我发现很难调试,因为即使在LocalSettings.php
中包含以下行,也不会显示完整的错误消息:
error_reporting( E_ALL );
ini_set('display_errors', 1);
//... rest of the file ...
$wgShowExceptionDetails = true;
以下是我得到的堆栈示例:
#0 /srv/www/htdocs/wotp/cd/includes/db/Database.php(538): DatabaseBase->reportQueryError('Unknown column ...', 1054, 'SELECT languag...', 'cdDictList::exe...', false)
#1 /srv/www/htdocs/wotp/cd/includes/db/Database.php(874): DatabaseBase->query('SELECT languag...', 'cdDictList::exe...')
#2 /srv/www/htdocs/wotp/cd/extensions/CommunityDictionary/includes/cdDictList.class.php(30): DatabaseBase->select('user_dictionary...', Array, Array, 'cdDictList::exe...', Array, Array)
#3 /srv/www/htdocs/wotp/cd/includes/api/ApiMain.php(595): cdDictList->execute()
#4 /srv/www/htdocs/wotp/cd/includes/api/ApiMain.php(338): ApiMain->executeAction()
#5 /srv/www/htdocs/wotp/cd/includes/api/ApiMain.php(322): ApiMain->executeActionWithErrorHandling()
#6 /srv/www/htdocs/wotp/cd/api.php(115): ApiMain->execute()
#7 {main}
有没有办法知道隐藏在...
后面的内容,以便我知道哪一列是未知的?
答案 0 :(得分:1)
我自己找到了答案。以下是捕获异常并显示异常的代码:
try{
$result = $this -> dbr -> select(...select code here...);
}
catch (Exception $e){
error_log($e->getMessage());
ApiBase :: dieDebug( __METHOD__, $e->getMessage() );
}
然后以这种形式出现错误:
<error code="internal_api_error_MWException" info="error text">