Home >Backend Development >PHP Tutorial > thinkphp数据库的有关问题

thinkphp数据库的有关问题

WBOY
WBOYOriginal
2016-06-13 13:43:07804browse

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

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

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


PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

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



PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php return 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 中的所有内容后重试
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn