tbl_get_field.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Provides download to a given field defined in parameters.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Common functions.
  10. */
  11. // we don't want the usual PMA_Response-generated HTML above the column's data
  12. define('PMA_BYPASS_GET_INSTANCE', 1);
  13. require_once 'libraries/common.inc.php';
  14. require_once 'libraries/mime.lib.php';
  15. /* Check parameters */
  16. PMA_Util::checkParameters(
  17. array('db', 'table')
  18. );
  19. /* Select database */
  20. if (!$GLOBALS['dbi']->selectDb($db)) {
  21. PMA_Util::mysqlDie(
  22. sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
  23. '', ''
  24. );
  25. }
  26. /* Check if table exists */
  27. if (!$GLOBALS['dbi']->getColumns($db, $table)) {
  28. PMA_Util::mysqlDie(__('Invalid table name'));
  29. }
  30. /* Grab data */
  31. $sql = 'SELECT ' . PMA_Util::backquote($_GET['transform_key'])
  32. . ' FROM ' . PMA_Util::backquote($table)
  33. . ' WHERE ' . $_GET['where_clause'] . ';';
  34. $result = $GLOBALS['dbi']->fetchValue($sql);
  35. /* Check return code */
  36. if ($result === false) {
  37. PMA_Util::mysqlDie(__('MySQL returned an empty result set (i.e. zero rows).'), $sql);
  38. }
  39. /* Avoid corrupting data */
  40. @ini_set('url_rewriter.tags', '');
  41. PMA_downloadHeader(
  42. $table . '-' . $_GET['transform_key'] . '.bin',
  43. PMA_detectMIME($result),
  44. strlen($result)
  45. );
  46. echo $result;
  47. ?>