1 2 3 4 5 6 7 8 9 10 11 | < p class = "face" >:(</ p > < h1 >SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)</ h1 > < div class = "content" > < div class = "info" > < div class = "title" > < h3 >错误位置</ h3 > </ div > < div class = "text" > < p >FILE: /data/webroot/ThinkPHP/Library/Think/Db/Driver.class.php  LINE: 109</ p > </ div > </ div > |
1 2 3 4 5 6 7 8 9 10 11 12 | <?php return array ( 'DB_TYPE' => 'mysql' , 'DB_HOST' => '127.0.0.1' , 'DB_USER' => 'root' , 'DB_PWD' => '' , 'DB_PORT' => 3306, 'DB_NAME' => 'imooc_singcms' , 'DB_CHARSET' => 'utf8' , 'DB_PREFIX' => 'cms_' , ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php namespace Common\Model; use Think\Model; class AdminModel extends Model{ private $_db = '' ; public function __construct() { $this ->_db = M( 'admin' ); } public function getAdminByUsername( $username ) { $res = $this ->_db->where( 'username="' . $username . '"' )->find(); return $res ; } } |
1 2 | $ret = D( 'Admin' )->getAdminByUsername( $username ); print_r( $ret ); |
出错信息说是SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
是数据库的用户名密码写错了吗?