Configuration - adampatterson/Dingo-Framework GitHub Wiki

Database Settings

Open up application/config/development/db.php the file should look something like this:

config::set('db',array(

/* Default Connection */
'default'=>array(

	'driver'=>'mysql',       // Driver
	'host'=>'localhost',     // Host
	'username'=>'root',      // Username
	'password'=>'',          // Password
	'database'=>'test'       // Database

)

));

You may need to change the settings in the default sub-array to connect to your database. In Dingo, the database driver controls queries to the database. In order to connect to a database you must use the correct driver. So, to connect to a MySQL database you must set driver to mysql.

These are the database drivers included with Dingo:

  • MySQL: mysql
  • PostgreSQL: pgsql
  • SQLight: sqlight

Automatically Loading the Database Library

If you plan to use databasing a lot in your application then you should add db to the autoload_libraries array found in application/config/development/config.php.

Manually Loading the Database Library

To manually load the database class you can simply place the following code in a controller or model function:

load::library('db');

Multiple Database Connections

Dingo can support multiple database connections at one time. To configure additional database connections simply extend the db configuration array:

config::set('db',array(

/* Default Connection */
'default'=>array(

	'driver'=>'mysql',       // Driver
	'host'=>'localhost',     // Host
	'username'=>'root',      // Username
	'password'=>'',          // Password
	'database'=>'test'       // Database

),

/* Another Connection */
'backup'=>array(

	'driver'=>'pgsql',       // Driver
	'host'=>'localhost',     // Host
	'username'=>'root',      // Username
	'password'=>'',          // Password
	'database'=>'test'       // Database

)

));

You may then make queries from any additional connections you configure by using their key name. For example, to use the above added configuration you would specify the query to use the "backup" connection.

Note: Dingo does not actually connect to any databases until you attempt to make a query to a database. Only database connections you use are loaded. This is so server resources are not wasted.