public function exportData($db, $table, $crlf, $error_url, $sql_query, $aliases = array())
{
$db_alias = $db;
$table_alias = $table;
$this->initAlias($aliases, $db_alias, $table_alias);
if (!$this->first) {
if (!PMA_exportOutputHandler(',')) {
return false;
}
} else {
$this->first = false;
}
$buffer = $this->encode(array('type' => 'table', 'name' => $table_alias, 'database' => $db_alias, 'data' => "@@DATA@@"));
list($header, $footer) = explode('"@@DATA@@"', $buffer);
if (!PMA_exportOutputHandler($header . $crlf . '[' . $crlf)) {
return false;
}
$result = $GLOBALS['dbi']->query($sql_query, null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED);
$columns_cnt = $GLOBALS['dbi']->numFields($result);
$columns = array();
for ($i = 0; $i < $columns_cnt; $i++) {
$col_as = $GLOBALS['dbi']->fieldName($result, $i);
if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
}
$columns[$i] = stripslashes($col_as);
}
$record_cnt = 0;
while ($record = $GLOBALS['dbi']->fetchRow($result)) {
$record_cnt++;
// Output table name as comment if this is the first record of the table
if ($record_cnt > 1) {
if (!PMA_exportOutputHandler(',' . $crlf)) {
return false;
}
}
$data = array();
for ($i = 0; $i < $columns_cnt; $i++) {
$data[$columns[$i]] = $record[$i];
}
if (!PMA_exportOutputHandler($this->encode($data))) {
return false;
}
}
if (!PMA_exportOutputHandler($crlf . ']' . $crlf . $footer . $crlf)) {
return false;
}
$GLOBALS['dbi']->freeResult($result);
return true;
}