Database Introduction

Introduction

Fuel offers a driver based database abstraction layer. At the time of writing supported drivers are MySQL, MySQLi and PDO. Aside from regular database interaction, fuel also comes with a DBUtil class to perform database operations such as creating databases, adding fields and much more.

Please note that not all features are supported by every driver.

Configuration

In order to begin working with databases, you must change the database settings. The database config file is located at APPPATH/config/db.php.

Database configurations are formated like so:

// a MySQL driver configuration
'development' => array(
	'type'           => 'mysqli',
	'connection'     => array(
		'hostname'       => 'localhost',
		'port'           => '3306',
		'database'       => 'fuel_db',
		'username'       => 'your_username',
		'password'       => 'y0uR_p@ssW0rd',
		'persistent'     => false,
	),
	'table_prefix'   => '',
	'charset'        => 'utf8',
	'enable_cache'   => true,
	'profiling'      => false,
),

// a PDO driver configuration
'production' => array(
	'type'           => 'pdo',
	'connection'     => array(
		'dsn'            => 'mysql:host=localhost;dbname=fuel_db',
		'username'       => 'your_username',
		'password'       => 'y0uR_p@ssW0rd',
		'persistent'     => false,
	),
	'table_prefix'   => '',
	'charset'        => 'utf8',
	'enable_cache'   => true,
	'profiling'      => false,
),

All Config Settings

Setting Type Description
type string What type of connection to use. Can be mysq, mysqli or pdo.
connection array Connection settings array
connection.dns string Connection DNS for PDO.
connection.username string Connection user.
connection.password string Connection password.
connection.persistent boolean Wether to initiate a persisten connection.
table_prefix string Table prefix.
charset string Connection charset.
enable_cache boolean Wether to allow caching, will overwrite query cache settings on a connection basis.
profiling boolean Wether to add the connections queries to the profiler.

Once you have your configuration in place, it's time to use it.