Translated using Weblate (Portuguese)
[phpmyadmin.git] / tbl_get_field.php
blob6501139dcc3a03e881b4a2d44ca48acf2f2a55cf
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 global $containerBuilder;
21 require_once ROOT_PATH . 'libraries/common.inc.php';
23 /** @var Response $response */
24 $response = $containerBuilder->get(Response::class);
26 /** @var DatabaseInterface $dbi */
27 $dbi = $containerBuilder->get(DatabaseInterface::class);
29 /** @var string $db */
30 $db = $containerBuilder->getParameter('db');
32 /** @var string $table */
33 $table = $containerBuilder->getParameter('table');
35 $response->disable();
37 /* Check parameters */
38 PhpMyAdmin\Util::checkParameters(
40 'db',
41 'table',
45 /* Select database */
46 if (! $dbi->selectDb($db)) {
47 PhpMyAdmin\Util::mysqlDie(
48 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
49 '',
50 false
54 /* Check if table exists */
55 if (! $dbi->getColumns($db, $table)) {
56 PhpMyAdmin\Util::mysqlDie(__('Invalid table name'));
59 /* Grab data */
60 $sql = 'SELECT ' . PhpMyAdmin\Util::backquote($_GET['transform_key'])
61 . ' FROM ' . PhpMyAdmin\Util::backquote($table)
62 . ' WHERE ' . $_GET['where_clause'] . ';';
63 $result = $dbi->fetchValue($sql);
65 /* Check return code */
66 if ($result === false) {
67 PhpMyAdmin\Util::mysqlDie(
68 __('MySQL returned an empty result set (i.e. zero rows).'),
69 $sql
73 /* Avoid corrupting data */
74 ini_set('url_rewriter.tags', '');
76 Core::downloadHeader(
77 $table . '-' . $_GET['transform_key'] . '.bin',
78 Mime::detect($result),
79 strlen($result)
81 echo $result;