Connecting to database

The Database library allows you to run various database queries and fetch results. System automatically loads the library and connects to the database which is available via $this->db You may also connect to another database manually if necessary.

Connecting to database

$config = array(
	'driver' => 'mysqli', // database driver
	'hostname' => 'localhost', // hostname
	'port' => '', // leave empty for default
	'username' => 'user',
	'password' => 'pass',
	'database' => 'db',
	'prefix' => 'tbl_', // optional table prefix
	'debug' => false, // if enabled, query errors will be displayed
	'strict' => false, // strict mode
	'autoinit' => true, // automatically connect to the database
loader::library('db', $config, 'my_db');
// You may now access database library via $this->my_db

You may also connect to the database manually:

// Set 'autoinit' to 'false' in the $config
$config['autoinit'] = false;

If database connection/selection fails, system will display an error. If you would rather not display anything, pass the "true" parameter to those functions and they'll return "false" if error occurs instead of displaying it: