{ID} - 3.4.1 Konfigurasi Database
Di CakePHP detail konfigurasi database disimpan di dalam sebuah file, yaitu di app/config/database.php. Contoh dari file konfigurasi database dapat dilihat di app/config/database.php.default. Sebuah konfigurasi yang sudah benar seharusnya aan terlihat kurang lebih seperti ini :
var $default = array('driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakephpuser',
'password' => 'c4k3roxx!',
'database' => 'my_cakephp_project',
'prefix' => '');
var $default = array('driver' => 'mysql','persistent' => false,'host' => 'localhost','login' => 'cakephpuser','password' => 'c4k3roxx!','database' => 'my_cakephp_project','prefix' => '');
Secara default, $default lah yang akan digunakan, kecuali disebutkan lain di dalam $useDbConfig di dalam sebuah model. Sebagai contoh, jika aplikasi saya memiliki database legacy sebagai tambahan yang di default, saya bisa menggunakannya di dalam model dengan membuat koneksi baru ke database $legacy yang array nya kurang lebih sama dengan array $default. Caranya adalah dengan menset var $useDbConfig = `legacy` pada model bersangkutan.
Isilah nilai / pasangan isi di dalam array konfigurasi sesuai kebutuhan anda.
| Key | Value |
|---|---|
| driver | Nama dari driver database yang akan digunakan disini. Examples: mysql, postgres, sqlite, pear-drivername, adodb-drivername, mssql, oracle, or odbc. |
| persistent | Perlu tidaknya menggunakan koneksi secara persistent ke dalam database. |
| host | hostname dari server database (atau alamat IP address nya). |
| login | Username yang digunakan untuk login ke dalam database. |
| password | Password yang digunakan untuk login ke dalam database. |
| database | Nama dari database yang akan digunakan. |
| prefix (optional) | Sebuah String yang digunakan sebagai prefiks dari setiap tabel di dalam database. Jika anda tidak menggunakan prefiks pada nama tabel anda, kosongkan bagian ini. |
| port (optional) | Port TCO atau Unix socket melakukan koneksi ke database server. |
| encoding | Menentukan karakter apa yang digunakan untuk mengirimkan pernyataan SQL ke server. |
| schema | Digunakan pada database PostgreSQL untuk menentukan schema mana yang akan digunakan. |
Setting prefix adalah untuk tabel, bukan model. Sebagai contoh, jika anda membuat tabel join untuk Apple dan Flavor model anda, anda menamakannya prefix_apples_flavors (not prefix_apples_prefix_flavors), dan menset prefix setting menjadi 'prefix_'.
Sampai disini, anda mungkin ingin melihat CakePHP Conventions. Penamaan yang benar untuk table anda (dan penambahkan beberapa kolom) bisa membawa anda ke fungsionalitas yang membebaskan, sehingga anda tidak perlu melakukan konfigurasi. Sebagai contoh, jika anda menamakan tabel database anda big_boxes, model anda BigBox, controller anda BigBoxesController, semuanya akan bekerja secara bersama - sama secara otomatis (tanpa konfigurasi). Dengan aturan konvensi, gunakan garis bawah, huruf kecil, dan bentuk jamak kata untuk setiap nama tabel di dalam database. Contoh : 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' => '');
var $default = array('driver' => 'mysql','persistent' => false,'host' => 'localhost','login' => 'cakephpuser','password' => 'c4k3roxx!','database' => 'my_cakephp_project','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-7 | Lines: 1-7 | ||
| - | <title>Database Configuration</title> | + | <title>Konfigurasi Database</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. | + | Di CakePHP detail konfigurasi database disimpan di dalam sebuah file, yaitu di app/config/database.php. Contoh dari file konfigurasi database dapat dilihat di app/config/database.php.default. Sebuah konfigurasi yang sudah benar seharusnya aan terlihat kurang lebih seperti ini : |
| </p> | </p> | ||
| <pre> | <pre> | ||
| var $default = array('driver' => 'mysql', | var $default = array('driver' => 'mysql', | ||
| 'persistent' => false, | 'persistent' => false, | ||
| Lines: 11-22 | Lines: 11-22 | ||
| 'database' => 'my_cakephp_project', | 'database' => 'my_cakephp_project', | ||
| 'prefix' => ''); | 'prefix' => ''); | ||
| </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. | + | Secara default, $default lah yang akan digunakan, kecuali disebutkan lain di dalam $useDbConfig di dalam sebuah model. Sebagai contoh, jika aplikasi saya memiliki database <em>legacy</em> sebagai tambahan yang di default, saya bisa menggunakannya di dalam model dengan membuat koneksi baru ke database $legacy yang array nya kurang lebih sama dengan array $default. Caranya adalah dengan menset var $useDbConfig = `legacy` pada model bersangkutan. |
| </p> | </p> | ||
| <p> | <p> | ||
| - | Fill out the key/value pairs in the configuration array to best suit your needs. | + | Isilah nilai / pasangan isi di dalam array konfigurasi sesuai kebutuhan anda. |
| </p> | </p> | ||
| <table> | <table> | ||
| <tr> | <tr> | ||
| <th> | <th> | ||
| Lines: 30-114 | Lines: 30-114 | ||
| <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. | + | Nama dari driver database yang akan digunakan disini. Examples: mysql, postgres, sqlite, pear-drivername, adodb-drivername, mssql, oracle, or 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. | + | Perlu tidaknya menggunakan koneksi secara <em>persistent</em> ke dalam database. |
| </td> | </td> | ||
| </tr> | </tr> | ||
| <tr> | <tr> | ||
| <td> | <td> | ||
| host | host | ||
| </td> | </td> | ||
| <td> | <td> | ||
| - | The database server’s hostname (or IP address). | + | hostname dari server database (atau alamat IP address nya). |
| </td> | </td> | ||
| </tr> | </tr> | ||
| <tr> | <tr> | ||
| <td> | <td> | ||
| login | login | ||
| </td> | </td> | ||
| <td> | <td> | ||
| - | The username for the account. | + | Username yang digunakan untuk login ke dalam database. |
| </td> | </td> | ||
| </tr> | </tr> | ||
| <tr> | <tr> | ||
| <td> | <td> | ||
| password | password | ||
| </td> | </td> | ||
| <td> | <td> | ||
| - | The password for the account. | + | Password yang digunakan untuk login ke dalam database. |
| </td> | </td> | ||
| </tr> | </tr> | ||
| <tr> | <tr> | ||
| <td> | <td> | ||
| database | database | ||
| </td> | </td> | ||
| <td> | <td> | ||
| - | The name of the database for this connection to use. | + | Nama dari database yang akan digunakan. |
| </td> | </td> | ||
| </tr> | </tr> | ||
| <tr> | <tr> | ||
| <td> | <td> | ||
| prefix (<em>optional</em>) | prefix (<em>optional</em>) | ||
| </td> | </td> | ||
| <td> | <td> | ||
| - | The string that prefixes every table name in the database. If your tables don’t have prefixes, set this to an empty string. | + | Sebuah <em>String</em> yang digunakan sebagai prefiks dari setiap tabel di dalam database. Jika anda tidak menggunakan prefiks pada nama tabel anda, kosongkan bagian ini. |
| </td> | </td> | ||
| </tr> | </tr> | ||
| <tr> | <tr> | ||
| <td> | <td> | ||
| port (<em>optional</em>) | port (<em>optional</em>) | ||
| </td> | </td> | ||
| <td> | <td> | ||
| - | The TCP port or Unix socket used to connect to the server. | + | Port TCO atau Unix socket melakukan koneksi ke database server. |
| </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. | + | Menentukan karakter apa yang digunakan untuk mengirimkan pernyataan SQL ke server. |
| </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. | + | Digunakan pada database PostgreSQL untuk menentukan schema mana yang akan digunakan. |
| </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 class="note">Setting prefix adalah untuk tabel, <strong>bukan</strong> model. Sebagai contoh, jika anda membuat tabel join untuk Apple dan Flavor model anda, anda menamakannya prefix_apples_flavors (<strong>not</strong> prefix_apples_prefix_flavors), dan menset prefix setting menjadi '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. | + | Sampai disini, anda mungkin ingin melihat <a href="/view/22/cakephp-conventions">CakePHP Conventions</a>. Penamaan yang benar untuk table anda (dan penambahkan beberapa kolom) bisa membawa anda ke fungsionalitas yang membebaskan, sehingga anda tidak perlu melakukan konfigurasi. Sebagai contoh, jika anda menamakan tabel database anda big_boxes, model anda BigBox, controller anda BigBoxesController, semuanya akan bekerja secara bersama - sama secara otomatis (tanpa konfigurasi). Dengan aturan konvensi, gunakan garis bawah, huruf kecil, dan bentuk jamak kata untuk setiap nama tabel di dalam database. Contoh : bakers, pastry_stores, savory_cakes. |
| </p> | </p> | ||
