Table of Contents
Your app/config/database.php file is where your
database configuration all takes place. A fresh install doesn't have a
database.php, so you'll need to make a copy of
database.php.default. Once you've made a copy and
renamed it you'll see the following:
Example 4.1. app/config/database.php
var $default = array('driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'project_name',
'prefix' => '');
Replace the information provided by default with the database connection information for your application.
One note about the prefix key: the string you enter there will be prepended to any SQL call that Cake makes to your database when working with tables. You define it here once so you don't have to specify it in other places. It also allows you to follow Cake's table naming conventions if you're on a host that only gives you a single database. Note: for HABTM join tables, you only add the prefix once: prefix_apples_bananas, not prefix_apples_prefix_bananas.
CakePHP supports the following database drivers:
mysql
postgres
sqlite
pear-drivername (so you might enter pear-mysql, for example)
adodb-drivername
The 'connect' key in the $default connection allows you to specify whether or not the database connection will be treated as persistent or not. Read the comments in the database.php.default file for help on specifying connection types for your database setup.
Your database tables should also follow the following conventions:
Table names used by Cake should consist of English words in plural, like "users", "authors" or "articles". Note that corresponding models have singular names.
Your tables must have a primary key named 'id'.
If you plan to relate tables, use foreign keys that look like: 'article_id'. The table name is singular, followed by an underscore, followed by 'id'.
If you include a 'created' and/or 'modified' column in your table, Cake will automatically populate the field when appropriate.
You'll also notice that there is a $test connection setting included in the database.php file. Fill out this configuration (or add other similarly formatted configurations) and use it in your application by placing something like:
var $useDbConfig = 'test';
Inside one of your models. You can add any number of additional connection settings in this manner.