18
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

cakephp 【DB接続エラー】

【備忘録】 cakephp導入時の設定

cakephpを導入、諸々の初期設定、DBの作成後、bakeを実行するとMysqlに接続できないとエラー

ターミナル
Error: Database connection "Mysql" is missing, or could not be created.

cakephpのルートでは緑文字で

Your database configuration file is present.

と出ていて、Mysqlの接続は確認済み。

PDOの設定の問題かと思いphpinfo()で確認するも設定済み


■対策

database.php内の"host"を、"localhost"→"127.0.0.1"に変えることで解決

database.php
    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => '',
        'password' => '',
        'database' => '',
        'prefix' => '',
        'encoding' => 'utf8',
    );

これを下記に変更

database.php
    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '127.0.0.1',
        'login' => '',
        'password' => '',
        'database' => '',
        'prefix' => '',
        'encoding' => 'utf8',
    );
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
18
Help us understand the problem. What are the problem?