05.6 Db Functions
Peter Ivanov edited this page Aug 20, 2013
·
1 revision
Allows you to get and filter data from the db, and caches the result.
Usage of the get($params)
function
//you can pass params as string
$data = get('table=my_table&id=5');
//or as array
$get_params = array('table'=>'content','id'=>5);
$data = get($get_params);
Parameters
parameter | description | usage |
---|---|---|
table |
your database table | get('table=content') |
single |
if set to true will return only the 1st row as array | get('table=content&id=5&single=true') |
orderby |
you can order by any field name | get('table=content&orderby=id desc') |
count |
if set to true it will return the results count | get('table=content&count=true') |
limit |
set limit of the returned dataset | get('table=content&limit=10') |
curent_page |
set offset of the returned dataset | get('table=content&limit=10&curent_page=2') |
$fieldname | you can filter data by passing your fields as params | get('table=content&my_field=value') |
Allows you to save in the database
Usage of the save($table, $data)
function
$data = array();
$data['id'] = 0;
$data['title'] = 'My title';
$data['content'] = 'My content';
$data['allow_html'] = true; //if true will allow you to save html
$saved_id = save('content',$data);
Parameters
parameter | description | usage |
---|---|---|
$table |
the name of your database table |
save('my_table',$data) , save('users',$data)
|
$data |
a key=>value array of your data to save | $saved_id = save('content',array('id'=>5,'title'=>"My title")); |