Cuppa Documentation

Find information related with: installation, user interface, best practices, improve and extend de functionalities, front-end integration and more.
Database

insert( $ table , $data, $return_row = false, $object_return = false )

$data = new stdClass();
$data->name = " 'Tufik Chediak' "; // remember, string values should be between ' '
$data->age = 18;
$data->date = "NOW()"; // this string put the current date in a field with the type date

$cuppa->dataBase->insert('users', $data); // insert on table users and return 1 or 0
$cuppa->dataBase->insert('users', $data, true); // insert on table users and return the row inserted like an array
$cuppa->dataBase->insert('users', $data, true, true); // insert on table users and return the row like an object

add($table, $data, $return_row = false, $object_return = false )

This method try to insert the row, if is no possible because there are a row with that info, update the info, use this method if want create only 1 method to insert and update.

$data = new stdClass();
$data->name = " 'Tufik Chediak' "; // remember, string values should be between ' '
$data->age = 18;

$cuppa->dataBase->add('users', $data);   // in this case, the method insert a new row and return 1 or 0

---

$data = new stdClass();
$data->id = 5;
$data->name = " 'Andres Jose' ";
$data->age = 25;

$cuppa->dataBase->add('users', $data);  // in this case, the method update the row with the id = 5 and return 1 or 0

update($table, $data, $condition, $return_row = false, $object_return = false )

$data = new stdClass();
$data->age = 25;

$cuppa->dataBase->update('users', $data, 'id = 5'); // update the row with the id = 5 and return 1 or 0
$cuppa->dataBase->update('users', $data, 'id = 5', true); // update the row with the id = 5 and return the info like an array
$cuppa->dataBase->update('users', $data, 'id = 5', true, true); // update the row with the id = 5 and return the info like an object

getRow($table, $condition, $object_return = false )

$cuppa->dataBase->getRow('articles', " id  = 2 AND language = 'es' " ) // return the info with the specific condition like an array
$cuppa->dataBase->getRow('articles', " id = 2 AND language = 'es' " ) // return the info with the specific condition like an object

getList($table, $condition = '', $limit = '', $order_by = '', $object_return = false )

$cuppa->dataBase->getList('news'); // return all info in the table
$cuppa->dataBase->getList('news', 'enabled = 1', 20, 'date DESC', true); // return 20 rows in the table news ordered with date DESC and with the condition like a object

delete($table, $condition )

$cuppa->dataBase->delete('news', 'id = 4'); // delete and return 1 or 0

sql($sql, $object_return = false )

$sql = 'SELECT * FROM articles';

cuppa->dataBase->sql(sql, true); // Execute the SQL Script, return 1, 0 or the info with a object

getTotalRows($table, $condition = '', $limit = '', $order_by = '' )

$cuppa->dataBase->getTotalRows('articles') // return the total rows on the table

getError()

$cuppa->dataBase->getError() // return an array with the code and message of the last error registered on MySQL

getColums($table )

$cuppa->dataBase->getColums('articles') // returnarray with all columns on the table

getTables()

$cuppa->dataBase->getTables() // return array with all tables on Database

ajust($object, $object_return = false )

Add ' ' to all data to the object or array: example: name => 'name' an return the new values.

$data = new stdClass();
$data->name = " Andres Jose";
$data->gender= "Male";
$data->age = 25;

$data = $cuppa->dataBase->ajust($data, true) // add to the string ' ' and return like object

lastId($table, $id_column = "id" )

Return the las id registered

$id = $cuppa->dataBase->lastId('articles') // return the last id on the articles table

getRoadPath($table, $data, $id_column, $parent_column, $return_column, $return_string = false, $language = null, $frienly_convertion = false)

++ table categories
+  id, alias, parent  
+  1, category-1, 0
+  2, category-1-1, 1
+  3, category-2, 0
+  4, category-2-1, 3
+  5, category-2-1-1, 4 
++

$path = $cuppa->dataBase->getRoadPath('categories', '5', 'id', 'parent', 'alias', true);
// return a string with the path just the node 5: category-2/category-2-1/