CI将数据库错误提示由Line Number: 330改为具体的行

在CI框架中,当数据库出现错误的时候,在windows系统中会提示:

Error Number: 1146
Table ‘article.hd_article0’ doesn’t exist
SELECT title, aid FROM (hd_article0) ORDER BY time desc LIMIT 10
Filename: E:\wamp\www\article\system\database\DB_driver.php
Line Number: 330

不管是哪个文件中的SQL语句错误,都定位到DB_driver.php的330行,这显然是不正确的。

而在Linux系统中则一切正常:

Error Number: 1146
Table ‘article.hd_article0’ doesn’t exist
SELECT title, aid FROM (hd_article0) ORDER BY time desc LIMIT 10
Filename: /var/www/html/article/models/article_model.php
Line Number: 38

解决方法:
在system/database/DB_driver.php文件中找到:
if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
改为:
if (isset($call['file']) && strpos($call['file'], FCPATH.SYSDIR.DIRECTORY_SEPARATOR.'database') === FALSE)

修改后的显示:

Error Number: 1146
Table ‘article.hd_article0’ doesn’t exist
SELECT title, aid FROM (hd_article0) ORDER BY time desc LIMIT 10
Filename: E:\wamp\www\article\application\models\article_model.php
Line Number: 38