Exports all the tables selected from database

@return null
425672
private function exportTables()
    {
        // Exporting tables one by one
        foreach ($this->tables as $table) {
            if ($this->matches($table, $this->dumpSettings['exclude-tables'])) {
                continue;
            }
            $this->getTableStructure($table);
            if (false === $this->dumpSettings['no-data']) { // don't break compatibility with old trigger
                $this->listValues($table);
            } elseif (true === $this->dumpSettings['no-data']
                 || $this->matches($table, $this->dumpSettings['no-data'])) {
                continue;
            } else {
                $this->listValues($table);
            }
        }
    }
416785
public function all()
    {
        $table = trim(self::$table);
        if (!empty($table)) {
            $query = /** @lang text */
                "SELECT * FROM {$table}";


            if(!empty($this->groupby)){
                $query.=' GROUP BY '.$this->groupby;
            }

            if (!empty($this->order)) {
                $query .= $this->order;
            }


            //execute the query and return the data or error message
              return  $this->fetch($query);


        } else {
            static::$response["status"] = "error";
            static::$response["response"] = "Table name cannot be empty";
            static::$response["code"] = 5000;
            return static::terminate(static::$response);
        }
    }
589087
public function export()
    {
        $tableName = $this->db->quoteTableName($this->logTable);
        $sql = "INSERT INTO $tableName ([[level]], [[category]], [[log_time]], [[prefix]], [[message]])
                VALUES (:level, :category, :log_time, :prefix, :message)";
        $command = $this->db->createCommand($sql);
        foreach ($this->messages as $message) {
            list($text, $level, $category, $timestamp) = $message;
            if (!is_string($text)) {
                // exceptions may not be serializable if in the call stack somewhere is a Closure
                if ($text instanceof \Exception) {
                    $text = (string) $text;
                } else {
                    $text = VarDumper::export($text);
                }
            }
            $command->bindValues([
                ':level' => $level,
                ':category' => $category,
                ':log_time' => $timestamp,
                ':prefix' => $this->getMessagePrefix($message),
                ':message' => $text,
            ])->execute();
        }
    }
708032
public function getExportData()
    {
        $languages = Language::findAll($this->exportLanguages);
        $languageSources = LanguageSource::find()->all();
        $languageTranslations = LanguageTranslate::findAll(['language' => $this->exportLanguages]);

        $data = [
            'languages' => $languages,
            'languageSources' => $languageSources,
            'languageTranslations' => $languageTranslations,
        ];

        return $data;
    }
777416
public function getTables()
    {
        $query = $this
            ->getSelectQuery('tablename')
            ->from('pg_tables')
            ->where("tablename NOT LIKE 'pg\\_%'")
            ->where("tablename NOT LIKE 'sql\\_%'")
            ->getQuery();
        
        return $this->query($query);
    }
305191
public function cmdTruncateDatabase()
    {
        $all = $this->getParam('all');
        $tables = $this->getArguments();

        if (empty($tables) && empty($all)) {
            $this->errorAndExit($this->text('Invalid command'));
        }

        $confirm = null;

        if (!empty($tables)) {
            $confirm = $this->choose($this->text('Are you sure you want to empty the tables? It cannot be undone!'));
        } else if (!empty($all)) {
            $confirm = $this->choose($this->text('Are you sure you want to empty ALL tables in the database? It cannot be undone!'));
            $tables = $this->db->fetchColumnAll('SHOW TABLES');
        }

        if ($confirm === 'y') {
            foreach ($tables as $table) {
                $this->db->query("TRUNCATE TABLE `$table`")->execute();
            }
        }

        $this->output();
    }
1115114
public function rawSelectAll()
        {
            $query = new Query($this);
            $query->generateSelectSQL(true);

            return Statement::getPreparedStatement($query)->execute();
        }
1215529
public function export()
    {
        $tableName = Podium::getInstance()->db->quoteTableName($this->logTable);
        $sql = "INSERT INTO $tableName ([[level]], [[category]], [[log_time]], [[ip]], [[message]], [[model]], [[user]])
                VALUES (:level, :category, :log_time, :ip, :message, :model, :user)";
        $command = Podium::getInstance()->db->createCommand($sql);
        foreach ($this->messages as $message) {
            list($text, $level, $category, $timestamp) = $message;
            $extracted = [
                'msg'   => '',
                'model' => null,
            ];
            if (is_array($text) && (isset($text['msg']) || isset($text['model']))) {
                if (isset($text['msg'])) {
                    if (!is_string($text['msg'])) {
                        $extracted['msg'] = VarDumper::export($text['msg']);
                    } else {
                        $extracted['msg'] = $text['msg'];
                    }
                }
                if (isset($text['model'])) {
                    $extracted['model'] = $text['model'];
                }
            } elseif (is_string($text)) {
                $extracted['msg'] = $text;
            } else {
                $extracted['msg'] = VarDumper::export($text);
            }
            if (substr($category, 0, 14) == 'bizley\podium\\') {
                $category = substr($category, 14);
            }
            $request = Yii::$app->getRequest();
            $command->bindValues([
                ':level'    => $level,
                ':category' => $category,
                ':log_time' => $timestamp,
                ':ip'       => $request instanceof Request ? $request->getUserIP() : null,
                ':message'  => $extracted['msg'],
                ':model'    => $extracted['model'],
                ':user'     => Log::blame(),
            ])->execute();
        }
    }
1042894
public function getAllTables()
    {
        return $this->connection->select(
            $this->grammar->compileGetAllTables($this->connection->getConfig('schema'))
        );
    }
1002431
protected function export()
    {
        $filesystem = new Filesystem();
        $handle = fopen($this->config['path'] . $this->prefix, "w");

        $checkPermissions = true;
        if (PHP_SAPI == 'cli') {
            $checkPermissions = false;
        }

        if (!$this->export->Init(
            $handle,
            $this->config["id"],
            false,
            true,
            $this->session["work_dir"],
            $this->session["file_dir"],
            $checkPermissions
        )
        ) {
            throw new ExportException('Failed to initialize export');
        }

        $this->export->DoNotDownloadCloudFiles();
        $this->export->StartExport();

        $this->export->StartExportMetadata();
        $this->export->ExportProperties($this->session["property_map"]);
        $this->export->ExportSections(
            $this->session["section_map"],
            time(),
            $this->config['interval'],
            $this->config["sections"],
            $this->session["property_map"]
        );
        $this->export->EndExportMetadata();

        $this->export->StartExportCatalog();
        $this->export->ExportElements(
            $this->session["property_map"],
            $this->session["section_map"],
            time(),
            $this->config['interval'],
            0,
            $this->config["elements"]
        );
        $this->export->EndExportCatalog();

        $this->export->ExportProductSets();
        $this->export->EndExport();

        fclose($handle);
        $filesystem->remove($this->config['path']);
        $filesystem->rename($this->config['path'] . $this->prefix, $this->config['path'], true);
    }
813210
public function dump()
	{
		$tables   = App::get('db')->getTableList();
		$prefix   = App::get('db')->getPrefix();
		$excludes = [];
		$now      = new Date;
		$exclude  = '';
		$includes = (array)$this->arguments->getOpt('include-table', []);

		if (!$this->arguments->getOpt('all-tables'))
		{
			$this->output->addLine('Dumping database with all prefixed tables included');
			foreach ($tables as $table)
			{
				if (strpos($table, $prefix) !== 0 && !in_array(str_replace('#__', $prefix, $table), $includes))
				{
					$excludes[] = Config::get('db') . '.' . $table;
				}
				elseif (in_array(str_replace('#__', $prefix, $table), $includes))
				{
					$this->output->addLine('Also including `' . $table . '`');
				}
			}

			// Build exclude list string
			$exclude = '--ignore-table=' . implode(' --ignore-table=', $excludes);
		}
		else
		{
			$this->output->addLine('Dumping database with all tables included');
		}

		// Add save location option

		$home     = getenv('HOME');
		$hostname = gethostname();
		$filename = tempnam($home, "{$hostname}.mysql.dump." . $now->format('Y.m.d') . ".sql.");

		// Build command
		$cmd = "mysqldump -u " . Config::get('user') . " -p'" . Config::get('password') . "' " . Config::get('db') . " --routines {$exclude} > {$filename}";

		exec($cmd);

		// Print out location of file
		$this->output->addLine('File saved to: ' . $filename, 'success');
	}
650930
public function getTables()
    {
        if (!$this->_allTablesFetched) { // Fetch only once
            $tables = $this->getTableNames();
            // Fetch missing tables
            foreach ($tables as $table) {
                $this->getTable($table); // Discard result, still available in cache
            }
            // Sort cache
            ksort($this->_tables);
            // Set flag for subsequent invocations
            $this->_allTablesFetched = true;
        }
        return $this->_tables;
    }
244142
protected function exportControllers()
    {
        foreach ($this->controllers as $pathIn => $pathOut) {
            if ($this->files->exists($controller = app_path('Http/Controllers/'.$pathOut))
                && ! $this->option('force')) {
                if (! $this->confirm("The [{$pathOut}] controller already exists. Do you want to overwrite it?")) {
                    continue;
                }
            }

            $this->files->put(
                $controller,
                $this->compileStub($this->files->get(__DIR__.'/stubs/make/controllers/'.$pathIn))
            );
        }
    }
1181904
public function export() : array
    {
        return array_combine(
            $this->keys,
            array_map(function ($f) {
                return $this->getField($f);
            }, $this->keys)
        );
    }
1309938
public function all()
	{
		//build the select query
		$sql = $this->buildSelect();

		//set the value of the query string
		$this->query_string = $sql;

		//set the query excecution start time
		$query_start_time = microtime(true);

		//execute the sql query
		$result = $this->connector->execute($sql);

		//set the query excecution end time
		$query_stop_time = microtime(true);

		//get the query_excecution
		$query_excec_time = $query_stop_time - $query_start_time;


		//put this in try...catch block for better error handling
		try{

			//check if the query return an error and throw exception
			if ( $result === false ) 
			{
				//get the erro message
				$error = $this->connector->lastError();

				//throw exception
				throw new MySQLException(get_class(new MySQLException) . ' ' .$this->connector->lastError() . '<span class="query-string"> (' . $sql . ') </span>');

			}
			
		}

		//diplay error message
		catch(MySQLException $MySQLExceptionObject){

			//display error message
			$MySQLExceptionObject->errorShow();

		}


		//define container rows() array
		$result_array = array();

		//loop through resultset setting the values of arrays and objects
		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

			$result_array[] = $row;

		}

		//get the response object instance
		$this->responseObject
			->setQueryString($this->query_string)
			->setQueryTime($query_excec_time)
			->setFieldCount($result->field_count)
			->setNumRows($result->num_rows)
			->setQueryFields($result->fetch_fields())
			->setResultArray($result_array);

		//return the full response object
		return $this->responseObject;
	}
981639
public function actionExport() {
        // Initialize export array.
        $data = [
            'siteGroups' => [],
            'sites' => [],
            'routes' => [],
            'fieldGroups' => [],
            'volumes' => [],
            'transforms' => [],
            'tagGroups' => [],
            'categoryGroups' => [],
            'sections' => [],
            'fields' => [],
            'entryTypes' => [],
            'globalSets' => [],
            'userGroups' => [],
            'users' => [],
        ];
        // The list of exportable items.
        $exportList = [
            'sites' => [
                'bodyParam' => 'siteSelection',
                'postProcess' => [
                    'groupId' => 'siteGroups'
                ],
            ],
            'sections' => [
                'bodyParam' => 'sectionSelection',
                'postProcess' => [
                    'entryTypes' => 'entryTypes'
                ],
            ],
            'routes' => [
                'bodyParam' => 'routeSelection',
            ],
            'volumes' => [
                'bodyParam' => 'volumeSelection',
            ],
            'transforms' => [
                'bodyParam' => 'assetTransformSelection',
            ],
            'tagGroups' => [
                'bodyParam' => 'tagSelection',
            ],
            'categoryGroups' => [
                'bodyParam' => 'categorySelection',
            ],
            'fields' => [
                'bodyParam' => 'fieldSelection',
                'postProcess' => [
                    'groupId' => 'fieldGroups'
                ],
            ],
            'globalSets' => [
                'bodyParam' => 'globalSelection',
            ],
            'userGroups' => [
                'bodyParam' => 'userGroupSelection',
            ],
            'users' => [
                'bodyParam' => 'userSelection',
            ]
        ];

        foreach ($exportList as $processorName => $processorInfo) {
            $exportIds = Craft::$app->request->getBodyParam($processorInfo['bodyParam']);
            if ($exportIds) {
                foreach ($exportIds as $exportId) {
                    if ($processorName === 'routes') {
                        $exportObj = Architect::$processors->$processorName->exportByUid($exportId);
                    } else {
                        $exportObj = Architect::$processors->$processorName->exportById($exportId);
                    }

                    if (isset($processorInfo['postProcess'])) {
                        foreach ($processorInfo['postProcess'] as $postProcessKey => $postProcessorName) {
                            switch ($postProcessKey) {
                                case 'groupId':
                                    $groupName = Architect::$processors->$postProcessorName->exportById($exportObj[$postProcessKey]);
                                    if (\in_array($groupName, $data[$postProcessorName], false) === false) {
                                        $data[$postProcessorName][] = $groupName;
                                    }
                                    unset($exportObj[$postProcessKey]);
                                    break;
                                case 'entryTypes':
                                    if (isset($exportObj[$postProcessKey]) && \is_array($exportObj[$postProcessKey])) {
                                        $data[$postProcessorName] = array_merge($data[$postProcessorName], $exportObj[$postProcessKey]);
                                        unset($exportObj[$postProcessKey]);
                                    }
                                    break;
                            }
                        }
                    }

                    $data[$processorName][] = $exportObj;
                }
            }
        }

        foreach ($data as $key => $value) {
            if (\count($value) <= 0) {
                unset($data[$key]);
            }
        }

        $this->renderTemplate('architect/export_results', [ 'dump' => json_encode($data, JSON_PRETTY_PRINT) ]);
    }
1229090
public function dump(array $tables = array())
    {
        $result = null;

        if (empty($tables)) {
            $tables = $this->fetchAllTables();
        }

        // Building logic
        foreach ($tables as $table) {
            // Main SELECT query
            $select = $this->queryBuilder->clear()
                                         ->select('*')
                                         ->from($table)
                                         ->getQueryString();

            $stmt = $this->pdo->query($select);
            $fieldCount = $stmt->columnCount();

            // Append additional drop state
            $result .= $this->queryBuilder->clear()
                                          ->dropTable($table)
                                          ->getQueryString();;

            // Show how this table was created
            $createResult = $this->pdo->query(sprintf('SHOW CREATE TABLE %s', $table))->fetch();
            $result .=  "\n\n" . $createResult['Create Table'] . ";\n\n";

            // Start main loop
            for ($i = 0; $i < $fieldCount; $i++) {
                // Loop to generate INSERT statements
                while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
                    $values = array();

                    // Extra values and push them to $values array
                    for ($j = 0; $j < $fieldCount; $j++) {
                        // We need to ensure all quotes are properly escaped
                        $row[$j] = addslashes($row[$j]);

                        // Ensure its correctly escaped
                        $row[$j] = str_replace("\n", "\\n", $row[$j]);
                        $row[$j] = sprintf('"%s"', $row[$j]);

                        // Push the value
                        array_push($values, $row[$j]);
                    }

                    // Generate short INSERT statement
                    $result .= $this->queryBuilder->clear()
                                                  ->insertShort($table, $values)
                                                  ->getQueryString();

                    $result .= "\n";

                    // Free memory for next iteration
                    unset($vals);
                }
            }

            $result .= "\n";
        }

        return $result;
    }