Database
Please note: This page is under construction and has not been finished yet.
Use the following to retrieve the database class object
$sql = e107::getDb();
Selecting data from a database table
$sql->select($table, $fields = '*', $arg = '', $noWhere = false, $debug = false, $log_type = '', $log_remark = '')
Parameter | Type | Description | Mandatory? |
---|---|---|---|
table | string | Name of the database table | Yes |
fields | string | Comma separated list of fields or " * " or a single field name (get one); | |
arg | string|array | .... | |
noWhere | boolean | | |
debug | boolean | | |
log type | | | |
log_remark | | | |
$sql->select('tablename', 'field1, field2', 'field_id = 1');
$sql->select("comments", "*", "comment_item_id = '$id' AND comment_type = '1' ORDER BY comment_datestamp");
$sql->select("chatbox", "*", "ORDER BY cb_datestamp DESC LIMIT $from, ".$view, true);
$sql->select('user', 'user_id, user_name', 'user_id=:id OR user_name=:name ORDER BY user_name', array('id' => 999, 'name'=>'e107'))
Selecting, looping through and displaying selected data with the fetch() method:
$sql->select('tablename', 'field1, field2', 'field_id = 1');
while($row = $sql->fetch())
{
echo $row['field1'];
}
Inserting data into a database table:
$insert = array(
'data' => array('field1' => 'value1', 'field2' => 'value2'),
'WHERE' => 'field_id = 1'
);