Blog Details

Database Configuration



                                

* Database Configuration :-

 
  • The config file is located at  application/config/database.php
  • The config settings are stored in a multi-dimensional array with this prototype:
. $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = ""; $db['default']['database'] = "database_name"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = FALSE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; $db['default']['swap_pre'] = ""; $db['default']['autoinit'] = TRUE; $db['default']['stricton'] = FALSE;

* Explanation of Values:

 
  • 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: mysql, postgres, odbc, etc. Must be specified in lower case.
  • dbprefix - An optional table prefix which will added to the table name when running Active Record queries. This permits multiple CodeIgniter installations to share one database.
  • pconnect - TRUE/FALSE (boolean) - Whether to use a persistent connection.
  • db_debug - TRUE/FALSE (boolean) - Whether database errors should be displayed.
  • cache_on - TRUE/FALSE (boolean) - Whether database query caching is enabled, see also Databse Caching Class.
  • cachedir - The absolute server path to your database query cache directory.
  • char_set - The character set used in communicating with the database.
  • dbcollat - The character collation used in communicating with the database.
 

Manually Connecting to a Database :-

 
  • The first parameter of this function can optionally be used to specify a particular database group from your config file, or you can even submit connection values for a database that is not specified in your config file. Examples:
  • To choose a specific group from your config file you can do this:
  • $this->load->database(' group_name');
 

* Connecting to your Database :-

 
  • There are two ways to connect to a database:
 

1) Automatically Connecting

  The "auto connect" feature will load and instantiate the database class with every page load. To enable "auto connecting", add the word database to the library array, as indicated in the following file:   application/config/autoload.php  

2) Manually Connecting

 
  • If only some of your pages require database connectivity you can manually connect to your database by adding this line of code in any function where it is needed, or in your class constructor to make the database available globally in that class.
  • $this->load->database();


Categories

Php mysql

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote