You are here

public function FrxPDO::sqlData in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 plugins/FrxPDO.inc \FrxPDO::sqlData()

Get data based on file data block in the repository.

Parameters

String $block_name:

Array $parm_data:

Query $subQuery:

Overrides FrxDataSource::sqlData

File

plugins/FrxPDO.inc, line 77
General database engine used to do sql queries.

Class

FrxPDO
@file General database engine used to do sql queries.

Code

public function sqlData($sql, $options = array()) {

  // Load the block from the file
  $db = $this->db;
  $xml = '';

  // Load the types array based on data
  $this->types = isset($options['type']) ? $options['type'] : array();
  if ($sql && $db) {
    $sql = $this->te
      ->replace($sql);
    $rs = $db
      ->query($sql);
    $xml = new SimpleXMLElement('<table/>');
    $e = $db
      ->errorCode();
    if ($e != '00000') {
      $i = $db
        ->errorInfo();
      FrxReportGenerator::instance()
        ->error($i[2] . ':' . $sql, $i[2]);
    }
    else {
      if ($rs && $rs
        ->columnCount()) {
        $data = $rs
          ->fetchAll(PDO::FETCH_ASSOC);
        $rownum = 0;
        if ($data) {
          foreach ($data as $row) {
            $rownum++;
            $row_node = $xml
              ->addChild('row');
            $row_node['num'] = $rownum;
            foreach ($row as $key => $value) {
              $row_node
                ->addChild($key, htmlspecialchars($value));
            }
          }
        }
      }
    }
    if ($this->debug) {
      $d = '';
      if ($xml) {
        $d = htmlspecialchars($xml->asXML);
      }
      FrxReportGenerator::instance()
        ->debug('SQL: ' . $sql, '<pre> SQL:' . $sql . "\n XML: " . $d . "/n</pre>");
    }
    return $xml;
  }
}