CakePHP3でPostgreSQLの設定方法
以下のファイルで、DBの設定を記述する。
| 1 | /[sample_dir]/config/app.php | 
記載内容は以下のとおり。(一部抜粋)
driverをPostgresに変更して、★★の部分は任意の内容に書き換える。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |     'Datasources' => [         'default' => [             'className' => 'Cake\Database\Connection',             'driver' => 'Cake\Database\Driver\Postgres',             'persistent' => false,             'host' => 'localhost',             /**              * CakePHP will use the default DB port based on the driver selected              * MySQL on MAMP uses port 8889, MAMP users will want to uncomment              * the following line and set the port accordingly              */             //'port' => 'nonstandard_port_number',             'username' => '★★',             'password' => '★★',             'database' => 'test',             'encoding' => 'utf8',             'timezone' => 'UTC',             'cacheMetadata' => true,             'log' => false, | 
CakePHP3ではデフォルトで、Mysqlのドライバを参照する設定となっています。
そのため、Postgresqlを使用予定でphp-mysqlをインストールしていない場合は、以下のようなエラーが発生します。
| 1 | Database driver Cake\Database\Driver\Mysql cannot be used due to a missing PHP extension or unmet dependency | 
上記と同ファイル(app.php)内にある’default’と同様の’test’側も’driver’ => ‘Cake\Database\Driver\Postgres’に変える必要があります。
