Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / tbl_get_field.php
blobe5ec269235a8a83b5ee9e74341acdfb87555a8e5
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 */
9 /**
10 * Common functions.
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/mime.lib.php';
15 /* Check parameters */
16 PMA_Util::checkParameters(
17 array('db', 'table')
20 /* Select database */
21 if (!$GLOBALS['dbi']->selectDb($db)) {
22 PMA_Util::mysqlDie(
23 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
24 '', ''
28 /* Check if table exists */
29 if (!$GLOBALS['dbi']->getColumns($db, $table)) {
30 PMA_Util::mysqlDie(__('Invalid table name'));
33 /* Grab data */
34 $sql = 'SELECT ' . PMA_Util::backquote($_GET['transform_key'])
35 . ' FROM ' . PMA_Util::backquote($table)
36 . ' WHERE ' . $_GET['where_clause'] . ';';
37 $result = $GLOBALS['dbi']->fetchValue($sql);
39 /* Check return code */
40 if ($result === false) {
41 PMA_Util::mysqlDie(__('MySQL returned an empty result set (i.e. zero rows).'), $sql);
44 /* Avoid corrupting data */
45 @ini_set('url_rewriter.tags', '');
47 PMA_downloadHeader(
48 $table . '-' . $_GET['transform_key'] . '.bin',
49 PMA_detectMIME($result),
50 strlen($result)
52 echo $result;