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 中的所有內容後重試
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.