Translated using Weblate (Czech)
[phpmyadmin.git] / tbl_get_field.php
blobf62f3c3b113d1651702929dfc98628de3c516d2b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Provides download to a given field defined in parameters.
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Core;
11 use PhpMyAdmin\DatabaseInterface;
12 use PhpMyAdmin\Mime;
13 use PhpMyAdmin\Response;
15 if (! defined('ROOT_PATH')) {
16 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
19 require_once ROOT_PATH . 'libraries/common.inc.php';
21 /** @var Response $response */
22 $response = $containerBuilder->get(Response::class);
24 /** @var DatabaseInterface $dbi */
25 $dbi = $containerBuilder->get(DatabaseInterface::class);
27 /** @var string $db */
28 $db = $containerBuilder->getParameter('db');
30 /** @var string $table */
31 $table = $containerBuilder->getParameter('table');
33 $response->disable();
35 /* Check parameters */
36 PhpMyAdmin\Util::checkParameters(
38 'db',
39 'table',
43 /* Select database */
44 if (! $dbi->selectDb($db)) {
45 PhpMyAdmin\Util::mysqlDie(
46 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
47 '',
48 false
52 /* Check if table exists */
53 if (! $dbi->getColumns($db, $table)) {
54 PhpMyAdmin\Util::mysqlDie(__('Invalid table name'));
57 if (! isset($_GET['where_clause'])
58 || ! isset($_GET['where_clause_sign'])
59 || ! Core::checkSqlQuerySignature($_GET['where_clause'], $_GET['where_clause_sign'])
60 ) {
61 /* l10n: In case a SQL query did not pass a security check */
62 Core::fatalError(__('There is an issue with your request.'));
63 exit;
66 /* Grab data */
67 $sql = 'SELECT ' . PhpMyAdmin\Util::backquote($_GET['transform_key'])
68 . ' FROM ' . PhpMyAdmin\Util::backquote($table)
69 . ' WHERE ' . $_GET['where_clause'] . ';';
70 $result = $dbi->fetchValue($sql);
72 /* Check return code */
73 if ($result === false) {
74 PhpMyAdmin\Util::mysqlDie(
75 __('MySQL returned an empty result set (i.e. zero rows).'),
76 $sql
80 /* Avoid corrupting data */
81 ini_set('url_rewriter.tags', '');
83 Core::downloadHeader(
84 $table . '-' . $_GET['transform_key'] . '.bin',
85 Mime::detect($result),
86 strlen($result)
88 echo $result;