Database configuration Codeigniter framework

 To connect with database in CodeIgniter you have to change config file that store your database connection values (username, password, database name, etc.). The config

file is located at application/config/database.php.

The config file look like this.

$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()
);

Let’s discuss about above the config value.

Name ConfigDescription
dsnThe DSN connect string (an all-in-one configuration sequence).
hostnameThe hostname of your database server. Often this is ‘localhost’.
usernameThe username used to connect to the database.
passwordThe password used to connect to the database.
databaseThe name of the database you want to connect to.
dbdriverThe database type. ie: mysqli, postgre, odbc, etc. Must be specified in lower case.
dbprefixAn optional table prefix which will added to the table name when running Query Builder queries. This permits multiple CodeIgniter installations to share one database.
pconnectTRUE/FALSE (boolean) - Whether to use a persistent connection.
db_debugTRUE/FALSE (boolean) - Whether database errors should be displayed.
cache_onTRUE/FALSE (boolean) - Whether database query caching is enabled, see also Database Caching Class.
cachedirThe absolute server path to your database query cache directory.
char_setThe character set used in communicating with the database.
The character collation used in communicating with the database
dbcollatNote
Only used in the ‘mysql’ and ‘mysqli’ drivers.
swap_preA 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.
schemaThe database schema, defaults to ‘public’. Used by PostgreSQL and ODBC drivers.
encryptWhether 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 certificates 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)
compressWhether or not to use client compression (MySQL only).
strictonTRUE/FALSE (boolean) - Whether to force “Strict Mode” connections, good for ensuring strict SQL while developing an application.
portThe database port number. To use this value you have to add a line to the database config array.
$db['default']['port'] = 5432;

Comments

Popular posts from this blog

Codeigniter Pro Level Tips and Tricks

Login with Facebook in CodeIgniter

PHP - File Uploading