Merge remote-tracking branch 'origin/QA_4_5' into QA_4_5
[phpmyadmin.git] / tbl_get_field.php
blobbd055ce2d9c0c6f5df53d857a82563deef44d44d
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 // we don't want the usual PMA_Response-generated HTML above the column's data
13 define('PMA_BYPASS_GET_INSTANCE', 1);
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/mime.lib.php';
17 /* Check parameters */
18 PMA_Util::checkParameters(
19 array('db', 'table')
22 /* Select database */
23 if (!$GLOBALS['dbi']->selectDb($db)) {
24 PMA_Util::mysqlDie(
25 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
26 '', false
30 /* Check if table exists */
31 if (!$GLOBALS['dbi']->getColumns($db, $table)) {
32 PMA_Util::mysqlDie(__('Invalid table name'));
35 /* Grab data */
36 $sql = 'SELECT ' . PMA_Util::backquote($_GET['transform_key'])
37 . ' FROM ' . PMA_Util::backquote($table)
38 . ' WHERE ' . $_GET['where_clause'] . ';';
39 $result = $GLOBALS['dbi']->fetchValue($sql);
41 /* Check return code */
42 if ($result === false) {
43 PMA_Util::mysqlDie(
44 __('MySQL returned an empty result set (i.e. zero rows).'), $sql
48 /* Avoid corrupting data */
49 @ini_set('url_rewriter.tags', '');
51 PMA_downloadHeader(
52 $table . '-' . $_GET['transform_key'] . '.bin',
53 PMA_detectMIME($result),
54 /*overload*/mb_strlen($result, '8bit')
56 echo $result;