public function FrxPDO::data in Forena Reports 6
Same name and namespace in other branches
- 6.2 plugins/FrxPDO.inc \FrxPDO::data()
- 7 plugins/FrxPDO.inc \FrxPDO::data()
- 7.2 plugins/FrxPDO.inc \FrxPDO::data()
Get data based on file data block in the repository.
Parameters
String $block_name:
Array $parm_data:
Query $subQuery:
File
- plugins/
FrxPDO.inc, line 70 - General database engine used to do sql queries.
Class
- FrxPDO
- @file General database engine used to do sql queries.
Code
public function data($block_name, $params = array(), $clause = '') {
// Load the block from the file
$db = $this->db;
$block = $this
->load_block($block_name);
$xml = '';
if ($block['source'] && $this
->access($block['access']) && $db) {
$sql = $block['source'];
if ($clause) {
$sql = 'SELECT * FROM (' . trim($sql, ' ;') . ') forena_table ' . $clause;
}
$sql = $this->te
->replace($sql, $params);
$rs = $db
->query($sql);
$xml = new SimpleXMLElement('<table/>');
$e = $db
->errorCode();
if ($e != '00000') {
$i = $db
->errorInfo();
forena_error($i[2] . ':' . $sql, $i[2]);
}
else {
//$rs->debugDumpParams();
$data = $rs
->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as $row) {
$row_node = $xml
->addChild('row');
foreach ($row as $key => $value) {
$row_node
->addChild($key, htmlspecialchars($value));
}
}
}
if ($this->debug) {
if ($xml) {
$d = htmlspecialchars($xml->asXML);
}
forena_debug('SQL: ' . $sql, '<pre> SQL:' . $sql . "\n XML: " . $d . "/n</pre>");
}
return $xml;
}
}