PMA\libraries\plugins\export\ExportJson::exportData PHP Метод

exportData() публичный Метод

Outputs the content of a table in JSON format
public exportData ( string $db, string $table, string $crlf, string $error_url, string $sql_query, array $aliases = [] ) : boolean
$db string database name
$table string table name
$crlf string the end of line sequence
$error_url string the url to go back in case of error
$sql_query string SQL query for obtaining data
$aliases array Aliases of db/table/columns
Результат boolean Whether it succeeded
    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;
    }