Fetching result rows PDO style

This commit is contained in:
José Lorenzo Rodríguez 2010-10-16 10:22:50 -04:30
parent f772527445
commit cb16605805

View file

@ -317,26 +317,26 @@ class DboMysql extends DboSource {
} }
/** /**
* Enter description here... * Builds a map of the columns contained in a result
* *
* @param unknown_type $results * @param PDOStatement $results
*/ */
function resultSet(&$results) { function resultSet($results) {
if (isset($this->results) && is_resource($this->results) && $this->results != $results) { //if (isset($this->results) && is_resource($this->results) && $this->results != $results) {
mysql_free_result($this->results); // mysql_free_result($this->results);
} //}
$this->results =& $results; $this->results = $results;
$this->map = array(); $this->map = array();
$numFields = mysql_num_fields($results); $numFields = $results->columnCount();
$index = 0; $index = 0;
$j = 0; $j = 0;
while ($j < $numFields) { while ($j < $numFields) {
$column = mysql_fetch_field($results, $j); $column = $results->getColumnMeta($j);
if (!empty($column->table) && strpos($column->name, $this->virtualFieldSeparator) === false) { if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) {
$this->map[$index++] = array($column->table, $column->name); $this->map[$index++] = array($column['table'], $column['name']);
} else { } else {
$this->map[$index++] = array(0, $column->name); $this->map[$index++] = array(0, $column['name']);
} }
$j++; $j++;
} }
@ -345,16 +345,15 @@ class DboMysql extends DboSource {
/** /**
* Fetches the next row from the current result set * Fetches the next row from the current result set
* *
* @return unknown * @return mixed array with results fetched and mapped to column names or false if there is no results left to fetch
*/ */
function fetchResult() { function fetchResult() {
if ($row = mysql_fetch_row($this->results)) { if ($row = $this->results->fetch()) {
$resultRow = array(); $resultRow = array();
$i = 0;
foreach ($row as $index => $field) { foreach ($this->map as $col => $meta) {
list($table, $column) = $this->map[$index]; list($table, $column) = $meta;
$resultRow[$table][$column] = $row[$index]; $resultRow[$table][$column] = $row->{$meta[1]};
$i++;
} }
return $resultRow; return $resultRow;
} else { } else {