Yii报错:CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement

Yii报错:CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: CDbConnection failed to open the DB connection

遇到此情况可打开yii的debug,在项目根目录index.php文件中搜索“YII_DEBUG”,false修改为true即可进一步查看真正报错信息。

defined('YII_DEBUG') or define('YII_DEBUG',true);

打开debug后显示如下错误:

CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: CDbConnection failed to open the DB connection: SQLSTATE[HY000] [1130] Host 'xx.x.xxx.xxx' is not allowed to connect to this MySQL server. The SQL statement executed was: SELECT * FROM `user` `t` WHERE `t`.`id`=0 LIMIT 1

表示没有数据库连接权限。那么你可以点击如下链接进行操作:

https://blog.csdn.net/lyd135364/article/details/78604254

 

你可能感兴趣的:(YII,Yii报错处理及bug修复)