Categories > TinyButStrong general >

database plugin for dibi abstraction layer ?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: kle_py
Date: 2013-08-28
Time: 22:40

database plugin for dibi abstraction layer ?

I would like testing the database libarary dibi from http://dibiphp.com/ with tinybutstrong.

Until now i managed to create arrays of the retrieved rows and display them with TBS.

Can You give me some hint to make this work better or do You have plans to create a plugin for the dibi abstraction layer ?

Thank You
By: Skrol29
Date: 2013-08-29
Time: 00:25

Re: database plugin for dibi abstraction layer ?

Here is a Dibi plugin for TBS: (tested with Dibi 2.1.0)
function tbsdb_DIBI_open(&$Source, &$Query, $Prms = null) {
  if (is_object($Query) && (get_class($Query)=='DibiResult') ) {
    return $Query; // it a DibiResult object
  } else {
    if (is_null($Prms)) {
        $rs = dibi::query($Query);
    } else {
        $rs = dibi::query($Query, $Prms);
    }
    return $rs;
  }
}
function tbsdb_DIBI_fetch(&$Rs) {
  $rec = $Rs->fetch();
  if (is_object($rec)) $rec = (array) $rec;
  return $rec;
}
function tbsdb_DIBI_close(&$Rs) {
  $Rs->free();
}

And examples of usage:
// basic
$TBS->MergeBlock('myblock', 'DIBI', "SELECT c1, c2, c3 FROM table1");

// with an extra Dibi parameter
$TBS->MergeBlock('myblock', 'DIBI', "SELECT c1, c2, c3 FROM table1 WHERE c4 = %1", $id);

// with a Dibi Recordset
$rs = dibi::query($sql);
$TBS->MergeBlock('myblock', 'DIBI',$rs);

By: kle_py
Date: 2013-08-29
Time: 15:50

Re: database plugin for dibi abstraction layer ?

Thank You,

my first tests work like a charm ;)