thinkphp 資料庫連接解決思路
來源:互聯網
上載者:User
thinkphp 資料庫連接
我從網上下了一個thinkphp2.2的代碼,自己建了一個index.php,然後產生專案檔,很順利
,但是串連資料庫,一直連不上,My Code很簡單,
$model = new Model();
$model->query("select * from think_person;");
conf/config.php檔案
return array(
//'配置項'=>'配置值'
'DB_TYPE' => 'mysql', // 資料庫類型
'DB_HOST' => 'localhost', // 伺服器位址
'DB_NAME' => 'my_table', // 資料庫名
'DB_USER' => 'root', // 使用者名稱
'DB_PWD' => 'guozhixin', // 密碼
'DB_PORT' => '3306', // 連接埠
'DB_PREFIX' => 'think_', // 資料庫表首碼
'DB_SUFFIX' => '', // 資料庫表尾碼
'DB_FIELDTYPE_CHECK' => false, // 是否進列欄位類型檢查
'DB_FIELDS_CACHE' => true, // 啟用欄位緩衝
'DB_CHARSET' => 'utf8', // 資料庫編碼預設採用utf8
'DB_DEPLOY_TYPE' => 0, // 資料庫部署方式:0 集中式(單一伺服器),1 分布式(主從伺服器)
'DB_RW_SEPARATE' => false, // 資料庫讀寫是否分離 主從式有效
);
資訊完全正確,實在不知道怎麼回事了。
------解決方案--------------------
你的 conf/config.php 檔案檔案中有
'DB_PWD' => 'guozhixin', // 密碼
而錯誤資訊為
Access denied for user 'root'@'localhost' (using password: NO)
顯然是 config.php 未載入,或路徑不對
請刪除 Runtime 中的所有內容後重試