Skip to content

Files

Latest commit

 

History

History
63 lines (42 loc) · 1.67 KB

database_talker_doc.md

File metadata and controls

63 lines (42 loc) · 1.67 KB

For working with the database we have the...

DatabaseTalker!

It's pretty simple to use

$dbtalker = new DatabaseTalker();
$returned_rows = $dbtalker->select(array(
    'table' => 'some_table', 
    'where' => array('my_column' => 'value')
));

//or setting a main table to not have to pass it in every query
$dbtalker = new DatabaseTalker(array('main_table' => 'some_table'));

//no need to pass here
$dbtalker->select(array('where' => array('my_column' => 'value')));

//but can also override
$dbtalker->select(array(
    'table' => 'another_table', 
    'where' => array('another_column' => 'value')
));

For custom queries

$dbtalker = new DatabaseTalker();

//procedural queries
$rows_affected = $dbtalker->query('UPDATE some_table SET my_column = "super value" WHERE some_table_id = 1');

//select queries
$returned_rows = $dbtalker->retrieve('DESCRIBE some_table');

$returned_rows = $dbtalker->retrieve('SHOW PROCESSLIST');

$returned_rows = $dbtalker->retrieve('SELECT 1');

Functions available and arguments

  • select( $options = array() )

    • table = table to select from
    • fields = fields to select (field => as_name)
    • tables_join = tables to join
    • where = where to select
    • group_by = group by field or fields
    • order_by = order by field or fields
    • limit = number of limit
  • insert( $data, $options = array() )

    • table = table to insert into
  • update( $data, $options = array() )

    • table = table to update
    • where = where to update
  • delete( $options = array() )

    • table = table to delete from
    • where = where to delete