{KO} - 3.4.1 Database Configuration

CakePHP의 데이터베이스 구성 내용은 기본적으로 app/config/database.php 파일에 있어야 합니다. app/config/database.php.default는 데이터베이스 구성 예제 파일입니다. 다음과 같은 식으로 설정을 해주면 됩니다.

var $default = array('driver'      => 'mysql',
                     'persistent'  => false,
                     'host'        => 'localhost',
                     'login'       => 'cakephpuser',
                     'password'    => 'c4k3roxx!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');
  1. var $default = array('driver' => 'mysql',
  2. 'persistent' => false,
  3. 'host' => 'localhost',
  4. 'login' => 'cakephpuser',
  5. 'password' => 'c4k3roxx!',
  6. 'database' => 'my_cakephp_project',
  7. 'prefix' => '');

모델에서 $useDbConfig 속성으로 다른 연결을 지정해 주지 않는 한 $default라는 배열 타입의 연결을 사용합니다. 예를 들자면, 응용 프로그램에서 기본 데이터베이스 말고도 추가로 이전 버전 데이터베이스를 사용한다면 $default 배열과 비슷하게 $legacy라는 데이터베이스 연결 배열을 만들어 주고서 적절한 모델에서 var $useDbConfig = 'legacy'; 라고 해서 사용할 수 있습니다.

각자의 필요에 따라 구성 배열의 키/값 내용을 채워주면 됩니다.

driver 이 구성 배열이 쓰는 데이터베이스 드라이버의 이름. 예: mysql, postgres, sqlite, pear-드라이버명, adodb-드라이버명, mssql, oracle, odbc.
persistent 데이터베이스에 지속적인(persistent) 연결을 사용할 것인지 여부.
host 데이터베이스 서버의 호스트 이름 (또는 IP 주소).
login 사용자 계정 이름.
password 사용자 계정 암호.
database 이 연결에서 사용할 데이터베이스의 이름.
prefix (선택적) 데이터베이스의 모든 테이블 이름 앞에 추가할 문자열. 사용하려는 테이블이 접두 문자열을 사용하지 않는다면 빈 문자열로 설정하면 됩니다.
port (선택적) 서버에 연결하기 위한 TCP 포트 또는 유닉스 소켓.
encoding 서버로 SQL문을 보낼 때 사용할 문자셋.
schema PostgreSQL 데이터베이스 설정에서 사용할 스키마를 지정할 때 사용.

주의할 점은 prefix 설정이 테이블에 대한 것이지 모델에 대한 것이 아니라는 점입니다. 예를 들어 Apple 및 Flavor 모델에 대한 조인 테이블을 만들었다면 그 테이블의 이름을 (prefix_apples_prefix_flavors가 아니라) prefix_apples_flavors라고 짓고서 prefix를 ‘prefix_’로 설정해 주면 됩니다.

이쯤에서 CakePHP 관례를 살펴보는 것도 좋겠군요. 테이블의 (더불어 일부 컬럼의) 이름을 잘 지어주면 몇몇 기능들이 저절로 제공되며 설정을 생략할 수 있습니다. 예를 들어 데이터베이스 테이블의 이름을 big_boxes라고 하고, 모델 이름은 BigBox로, 컨트롤러는 BigBoxesController로 하면 자동으로 모든 게 동작합니다. 관례에 따라서 데이터베이스 테이블 이름에는 밑줄 문자와 소문자를 사용하며, 복수 형태를 씁니다. bakers, pastry_stores, savory_cakes 같은 식입니다.

{EN} - 3.4.1 Database Configuration

CakePHP expects database configuration details to be in a file at app/config/database.php. An example database configuration file can be found at app/config/database.php.default. A finished configuration should look something like this.

var $default = array('driver'      => 'mysql',
                     'persistent'  => false,
                     'host'        => 'localhost',
                     'login'       => 'cakephpuser',
                     'password'    => 'c4k3roxx!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');
  1. var $default = array('driver' => 'mysql',
  2. 'persistent' => false,
  3. 'host' => 'localhost',
  4. 'login' => 'cakephpuser',
  5. 'password' => 'c4k3roxx!',
  6. 'database' => 'my_cakephp_project',
  7. 'prefix' => '');

The $default connection array is used unless another connection is specified by the $useDbConfig property in a model. For example, if my application has an additional legacy database in addition to the default one, I could use it in my models by creating a new $legacy database connection array similar to the $default array, and by setting var $useDbConfig = ‘legacy’; in the appropriate models.

Fill out the key/value pairs in the configuration array to best suit your needs.

Key Value
driver The name of the database driver this configuration array is for. Examples: mysql, postgres, sqlite, pear-drivername, adodb-drivername, mssql, oracle, or odbc.
persistent Whether or not to use a persistent connection to the database.
host The database server’s hostname (or IP address).
login The username for the account.
password The password for the account.
database The name of the database for this connection to use.
prefix (optional) The string that prefixes every table name in the database. If your tables don’t have prefixes, set this to an empty string.
port (optional) The TCP port or Unix socket used to connect to the server.
encoding Indicates what character set the to use to send SQL statements to the server.
schema Used in PostgreSQL database setups to specify which schema to use.

The prefix setting is for tables, not models. For example, if you create a join table for your Apple and Flavor models, you name it prefix_apples_flavors (not prefix_apples_prefix_flavors), and set your prefix setting to 'prefix_'.

At this point, you might want to take a look at the CakePHP Conventions. The correct naming for your tables (and the addition of some columns) can score you some free functionality and help you avoid configuration. For example, if you name your database table big_boxes, your model BigBox, your controller BigBoxesController, everything just works together automatically. By convention, use underscores, lower case, and plural forms for your database table names - for example: bakers, pastry_stores, and savory_cakes.

Differences

Lines: 1-7Lines: 1-7
 <title>Database Configuration</title> <title>Database Configuration</title>
 <p> <p>
- CakePHP expects database configuration details to be in a file at app/config/database.php. An example database configuration file can be found at app/config/database.php.default. A finished configuration should look something like this. + CakePHP 데이터베이스 구성 내용은 기본적으로 app/config/database.php 파일에 있어야 합니다. app/config/database.php.default 데이터베이스 구성 예제 파일입니다. 다음과 같은 식으로 설정을 해주면 됩니다.
 </p> </p>
 <pre> <pre>
 var $default = array('driver' =&gt; 'mysql', var $default = array('driver' =&gt; 'mysql',
  'persistent' =&gt; false,  'persistent' =&gt; false,
Lines: 11-114Lines: 11-115
  'database' =&gt; 'my_cakephp_project',  'database' =&gt; 'my_cakephp_project',
  'prefix' =&gt; '');  'prefix' =&gt; '');
 </pre> </pre>
 <p> <p>
- The $default connection array is used unless another connection is specified by the $useDbConfig property in a model. For example, if my application has an additional legacy database in addition to the default one, I could use it in my models by creating a new $legacy database connection array similar to the $default array, and by setting var $useDbConfig = legacy; in the appropriate models. + 모델에서 $useDbConfig 속성으로 다른 연결을 지정해 주지 않는 한 $default라는 배열 타입의 연결을 사용합니다. 예를 들자면, 응용 프로그램에서 기본 데이터베이스 말고도 추가로 이전 버전 데이터베이스를 사용한다면 $default 배열과 비슷하게 $legacy라는 데이터베이스 연결 배열을 만들어 주고서 적절한 모델에서 var $useDbConfig = 'legacy'; 라고 해서 사용할 수 있습니다.
 </p> </p>
 <p> <p>
- Fill out the key/value pairs in the configuration array to best suit your needs. + 각자의 필요에 따라 구성 배열의 키/값 내용을 채워주면 됩니다.
 </p> </p>
 <table> <table>
  <tr>  <tr>
  <th>  <th>
- Key +
  </th>  </th>
  <th>  <th>
- Value +
  </th>  </th>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  driver  driver
  </td>  </td>
  <td>  <td>
- The name of the database driver this configuration array is for. Examples: mysql, postgres, sqlite, pear-drivername, adodb-drivername, mssql, oracle, or odbc. + 구성 배열이 쓰는 데이터베이스 드라이버의 이름. : mysql, postgres, sqlite, pear-드라이버명, adodb-드라이버명, mssql, oracle, odbc.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  persistent  persistent
  </td>  </td>
  <td>  <td>
- Whether or not to use a persistent connection to the database. + 데이터베이스에 지속적인(persistent) 연결을 사용할 것인지 여부.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  host  host
  </td>  </td>
  <td>  <td>
- The database server’s hostname (or IP address). + 데이터베이스 서버의 호스트 이름 (또는 IP 주소).
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  login  login
  </td>  </td>
  <td>  <td>
- The username for the account. + 사용자 계정 이름.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  password  password
  </td>  </td>
  <td>  <td>
- The password for the account. + 사용자 계정 암호.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  database  database
  </td>  </td>
  <td>  <td>
- The name of the database for this connection to use. + 연결에서 사용할 데이터베이스의 이름.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
- prefix (<em>optional</em>) + prefix (선택적)
  </td>  </td>
  <td>  <td>
- The string that prefixes every table name in the database. If your tables dont have prefixes, set this to an empty string. + 데이터베이스의 모든 테이블 이름 앞에 추가할 문자열. 사용하려는 테이블이 접두 문자열을 사용하 않는다면 문자열로 설정하면 됩니다.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
- port (<em>optional</em>) + port (선택적)
  </td>  </td>
  <td>  <td>
- The TCP port or Unix socket used to connect to the server. + 서버에 연결하기 위한 TCP 포트 또는 유닉스 소켓.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  encoding  encoding
  </td>  </td>
  <td>  <td>
- Indicates what character set the to use to send SQL statements to the server. + 서버로 SQL문을 보낼 사용할 문자셋.
  </td>  </td>
  </tr>  </tr>
  <tr>  <tr>
  <td>  <td>
  schema  schema
  </td>  </td>
  <td>  <td>
- Used in PostgreSQL database setups to specify which schema to use. + PostgreSQL 데이터베이스 설정에서 사용할 스키마를 지정할 사용.
  </td>  </td>
  </tr>  </tr>
 </table> </table>
-<p class="note">The prefix setting is for tables, <strong>not</strong> models. For example, if you create a join table for your Apple and Flavor models, you name it prefix_apples_flavors (<strong>not</strong> prefix_apples_prefix_flavors), and set your prefix setting to 'prefix_'.</p> 
 <p> <p>
- At this point, you might want to take a look at the <a href="/view/22/cakephp-conventions">CakePHP Conventions</a>. The correct naming for your tables (and the addition of some columns) can score you some free functionality and help you avoid configuration. For example, if you name your database table big_boxes, your model BigBox, your controller BigBoxesController, everything just works together automatically. By convention, use underscores, lower case, and plural forms for your database table names - for example: bakers, pastry_stores, and savory_cakes. + 주의할 점은 prefix 설정이 테이블에 대한 것이지 모델에 대한 것이 <strong&gt;아니라는</strong&gt; 점입니다. 예를 들어 Apple 및 Flavor 모델에 대한 조인 테이블을 만들었다면 그 테이블의 이름을 (prefix_apples_prefix_flavors가 &lt;strong>아니라</strong>) prefix_apples_flavors라고 짓고서 prefix를 ‘prefix_’로 설정해 주면 됩니다.
&l
t;/p> />&lt;p>
이쯤에서
<a href="/ko/view/22/cakephp-conventions">CakePHP 관례</a> 살펴보는 것도 좋겠군요. 테이블의 (더불어 일부 컬럼의) 이름을 지어주면 몇몇 기능들이 저절로 제공되며 설정을 생략할 있습니다. 예를 들어 데이터베이스 테이블의 이름을 big_boxes라고 하고, 모델 이름은 BigBox, 컨트롤러는 BigBoxesController 하면 자동으로 모든 동작합니다. 관례에 따라서 데이터베이스 테이블 이름에는 밑줄 문자와 소문자를 사용하며, 복수 형태를 씁니다. bakers, pastry_stores, savory_cakes 같은 식입니다.
 </p> </p>