读书人

thinkphp数据库的有关问题

发布时间: 2012-03-26 15:46:56 作者: rapoo

thinkphp数据库的问题
用thinkphp框架。new Model()的时候会出错。
Exception里的信息好像是

"Access denied for user 'root'@'localhost' (using password: NO)"

但是我已经在config.php里配置好信息了。
其中数据库名称为test,表为think_em。


PHP code
<?phpclass IndexAction extends Action{        public function index() {        try{            $Test = new Model('em');//这里出错,改成think_em也错。                //...        }catch (Exception $e){            dump($e);        }    }}?>


PHP code
<?phpreturn array(    //'配置项'=>'配置值'    'DB_TYPE'=>'mysql',    'DB_HOST'=>'localhost',    'DB_NAME'=>'test',    'DB_USER'=>'root',    'DB_PWD'=>'welcome',    'DB_PORT'=>'3306',    'DB_PREFIX'=>'think_',    'APP_DEBUG'=>true,);?>




[解决办法]
1:上面的错误意思是密码不对,检查一下密码和端口。

2:new Model('');改成:$test=M('Em');
[解决办法]
删除 Runtime 中的所有内容后重试

读书人网 >PHP

热点推荐