FUEL CMS User Guide : Version 1.5.2


MY_DB_mysql_driver Class

The MY_DB_mysql_driver Class extends CI_DB_mysql_driver driver class. It adds several methods listed below:

$this->db->debug_query([hidden], [exit])

Echos out the last query ran to the screen. The hidden parameter will wrap the echoed output into an HTML comment. The exit parameter will exit the script upon debugging.

$this->examples_model->db->debug_query();

$this->db->safe_select('table', [fields], [prefix])

Appends the table name to fields in a select that don't have it to prevent ambiguity. The fields parameter is an array of fields to create the select statement. By default it will do all the table fields. The prefix parameter will prefix the selected columns with string.

$select = $this->examples_model->db->safe_select('example');
$this->db->select($select);

$this->db->field_info('table', fields)

Gets an array of information about a particular table's field. The fields parameter is the field name to get information from.

$field_info = $this->examples_model->db->field_info('example', 'my_field');

$this->db->table_info('table', [set_field_key])

Gets an array of information about a particular table's field. The set_field_key parameter sets the array returned key to the column name. The default is TRUE

$table_info = $this->examples_model->db->table_info('example');
foreach($table_info as $field => $info)
{
	echo $info['name'].'
'; echo $info['type'].'
'; }

$this->db->insert_ignore('table', values, [primary_key])

Save's information to the database using INSERT IGNORE syntax The values parameter are the values to save to the database. The primary_key parameter is column to be used as the primary key. The default is id.

$field_info = $this->examples_model->db->field_info('example', 'my_field');

$this->db->get_query_string([$clear])

Allows you to get the compiled active record string without running the query. The clear parameter will by default clear the active record for subsequent queries. This method is an alias to active records _compile_select() method.

$this->db->select('my_field');
$this->db->from('my_table');
$this->db->where(array('active' => 'yes'));
$sql = $this->examples_model->db->get_query_string();
echo $sql; // SELECT my_field FROM my_table WHERE active = 'yes'

$this->db->clear_query_string()

Clears the compiled query string. This method is an alias to active records _reset_select() method.

$this->examples_model->db->select('my_field');
$this->examples_model->db->from('my_table');
$this->examples_model->db->where(array('active' => 'yes'));
$sql = $this->examples_model->db->get_query_string();
echo $sql; // SELECT my_field FROM my_table WHERE active = 'yes'
$this->examples_model->db->clear_query_string();
$sql = $this->examples_model->db->get_query_string();
echo $sql; // ""