Pimcore\Backup::mysqlData PHP Метод

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

public mysqlData ( $name, $type ) : array
$name
$type
Результат array
    public function mysqlData($name, $type)
    {
        $db = Db::reset();
        $dumpData = "\n\n";
        $name = $db->quoteTableAs($name);
        if ($type != "VIEW") {
            // backup tables
            $tableData = $db->fetchAll("SELECT * FROM " . $name);
            foreach ($tableData as $row) {
                $cells = [];
                foreach ($row as $cell) {
                    if (is_string($cell)) {
                        $cell = $db->quote($cell);
                    } elseif ($cell === null) {
                        $cell = "NULL";
                    }
                    $cells[] = $cell;
                }
                $dumpData .= "INSERT INTO " . $name . " VALUES (" . implode(",", $cells) . ");";
                $dumpData .= "\n";
            }
        } else {
            // dump view structure
            $dumpData .= "\n\n";
            $dumpData .= "DROP VIEW IF EXISTS " . $name . ";";
            $dumpData .= "\n";
            try {
                $viewData = $db->fetchRow("SHOW CREATE VIEW " . $name);
                $dumpData .= $viewData["Create View"] . ";";
            } catch (\Exception $e) {
                Logger::error($e);
            }
        }
        $dumpData .= "\n\n";
        $h = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql", "a+", false, File::getContext());
        fwrite($h, $dumpData);
        fclose($h);
        return ["success" => true];
    }