Database Configuration For php Framework Codeignator:
Database Configuration For
php Framework Codeignator:
You
can set database connection values for
specific environments by placing database.php it the respective environment config
folder. Codeigniter has config file lets
you store your database connection values (username, password,database name,etc)
the config file location at application/config/database.php
$db['default'] = array(
'dsn' => '',
'hostname'
=> 'localhost',
'username'
=> 'root',
'password'
=> '',
'database'
=> 'database_name',
'dbdriver'
=> 'mysqli',
'dbprefix'
=> '',
'pconnect'
=> TRUE,
'db_debug'
=> TRUE,
'cache_on'
=> FALSE,
'cachedir'
=> '',
'char_set'
=> 'utf8',
'dbcollat'
=> 'utf8_general_ci',
'swap_pre'
=> '',
'encrypt'
=> FALSE,
'compress'
=> FALSE,
'stricton'
=> FALSE,
'failover'
=> array()
);
Some
codeigniter such as Sessions require Query Builder to be enabled to access
certain functionality.#
DSN:
The DSN connect string (an all –in-one configuration sequence )
Hostname:The
hostname of your database server.often this is ‘localhost’.
UserName:
The username used to connect to the database.
Password:
The password used to connect to the database.
Database:
The name of the database you want to connect to.
dbdriver:
The database type .ie mysqli, postgre,odbc,etc. Must be specified in lower
case.
dbprefix:
An optional table prefix which will added to the table name when running Query
builder queries.This permits multiple Codeigniter installations to share one
database.
Pconnect:
TRUE/FALSE bollen – Whether to use a persistent connection.
Db_debug:TRUE?FALSE
Boolean – Whether database query caching is enabled see alaso Database caching
class.
Cachdir:
The absolute server path to your database query cache directory.
Char_set:
The character set used in communicating with the database the character
collation used in communicating with the database.
swap_pre: A default table
prefix that should be swapped with dbprefix. This is useful for distributed
applications where you might run manually written queries, and need the prefix
to still be customizable by the end user.
Schema:
The
database schema, defaults to ‘public’. Used by PostgreSQL and ODBC drivers.
Encrypt: Whether or not to use an encrypted connection.
‘mysql’ (deprecated), ‘sqlsrv’ and ‘pdo / sqlsrv’
drivers accept TRUE/FALSE
‘mysqli’ and ‘pdo/mysql’ drivers accept an array
with the following options:
‘ssl_key’ - Path to the private key file
‘ssl_cert’ - Path to the public key certificate
file
‘ssl_ca’ - Path to the certificate authority file
‘ssl_capath’ - Path to a directory containing
trusted CA certificats in PEM format
‘ssl_cipher’ - List of allowed ciphers to be
used for the encryption, separated by colons (‘:’)
‘ssl_verify’ - TRUE/FALSE; Whether to verify the
server certificate or not (‘mysqli’ only)
Port:$db['default']['port'] = 5432;
Some database drivers (such as PDO,
PostgreSQL, Oracle, ODBC) might require a full DSN string to be provided. If
that is the case, you should use the ‘dsn’ configuration setting, as if you’re
using the driver’s underlying native PHP extension, like this:// PDO
$db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
// Oracle
$db['default']['dsn'] = '//localhost/XE';
$db['default']['failover'] = array(
array(
'hostname' => 'localhost1',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE
),
array(
'hostname' => 'localhost2',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE
)
);
You can specify as many failovers as you
like.The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.) under a single installation, you can set up a connection group for each, then switch between groups as needed. For example, to set up a “test” environment you would do this:
$db['test'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'compress' => FALSE,
'encrypt' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
Then, to globally tell the system to use that
group you would set this variable located in the config file:$active_group = 'test';
The name ‘test’ is arbitrary . It can be anything you want . by default we’ve used the word “default” for the primary connection.

No comments