home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / xml.php < prev    next >
Encoding:
PHP Script  |  2003-11-20  |  4.2 KB  |  144 lines

  1. <?php
  2. /* $Id: xml.php,v 2.1 2003/11/20 16:31:51 garvinhicking Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Set of functions used to build XML dumps of tables
  7.  */
  8.  
  9. /**
  10.  * Outputs comment
  11.  *
  12.  * @param   string      Text of comment
  13.  *
  14.  * @return  bool        Whether it suceeded
  15.  */
  16. function PMA_exportComment($text) {
  17.     return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
  18. }
  19.  
  20. /**
  21.  * Outputs export header
  22.  *
  23.  * @return  bool        Whether it suceeded
  24.  *
  25.  * @access  public
  26.  */
  27. function PMA_exportHeader() {
  28.     global $crlf;
  29.     global $cfg;
  30.     
  31.     if ($GLOBALS['output_charset_conversion']) {
  32.         $charset = $GLOBALS['charset_of_file'];
  33.     } else {
  34.         $charset = $GLOBALS['charset'];
  35.     }
  36.  
  37.     $head  =  '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
  38.            .  '<!--' . $crlf
  39.            .  '-' . $crlf
  40.            .  '- phpMyAdmin XML Dump' . $crlf
  41.            .  '- version ' . PMA_VERSION . $crlf
  42.            .  '- http://www.phpmyadmin.net' . $crlf
  43.            .  '-' . $crlf
  44.            .  '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
  45.     if (!empty($cfg['Server']['port'])) {
  46.          $head .= ':' . $cfg['Server']['port'];
  47.     }
  48.     $head .= $crlf
  49.            .  '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
  50.            .  '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
  51.            .  '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
  52.            .  '-->' . $crlf . $crlf;
  53.     return PMA_exportOutputHandler($head);
  54. }
  55.  
  56. /**
  57.  * Outputs database header
  58.  *
  59.  * @param   string      Database name
  60.  *
  61.  * @return  bool        Whether it suceeded
  62.  *
  63.  * @access  public
  64.  */
  65. function PMA_exportDBHeader($db) {
  66.     global $crlf;
  67.     $head = '<!--' . $crlf
  68.           . '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
  69.           . '-->' . $crlf
  70.           . '<' . $db . '>' . $crlf;
  71.     return PMA_exportOutputHandler($head);
  72. }
  73.  
  74. /**
  75.  * Outputs database footer
  76.  *
  77.  * @param   string      Database name
  78.  *
  79.  * @return  bool        Whether it suceeded
  80.  *
  81.  * @access  public
  82.  */
  83. function PMA_exportDBFooter($db) {
  84.     global $crlf;
  85.     return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
  86. }
  87.  
  88. /**
  89.  * Outputs create database database
  90.  *
  91.  * @param   string      Database name
  92.  *
  93.  * @return  bool        Whether it suceeded
  94.  *
  95.  * @access  public
  96.  */
  97. function PMA_exportDBCreate($db) {
  98.     return TRUE;
  99. }
  100.  
  101.  
  102. /**
  103.  * Outputs the content of a table
  104.  *
  105.  * @param   string      the database name
  106.  * @param   string      the table name
  107.  * @param   string      the end of line sequence
  108.  * @param   string      the url to go back in case of error
  109.  * @param   string      SQL query for obtaining data
  110.  *
  111.  * @return  bool        Whether it suceeded
  112.  *
  113.  * @access  public
  114.  */
  115. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
  116.     $result      = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
  117.     
  118.     $columns_cnt = mysql_num_fields($result);
  119.     for ($i = 0; $i < $columns_cnt; $i++) {
  120.         $columns[$i] = stripslashes(mysql_field_name($result, $i));
  121.     }
  122.     unset($i);
  123.     
  124.     $buffer      = '  <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
  125.     if (!PMA_exportOutputHandler($buffer)) return FALSE;
  126.     
  127.     while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) {
  128.         $buffer         = '    <' . $table . '>' . $crlf;
  129.         for ($i = 0; $i < $columns_cnt; $i++) {
  130.             // There is no way to dectect a "NULL" value with PHP3
  131.             if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
  132.                 $buffer .= '        <' . $columns[$i] . '>' . htmlspecialchars(stripslashes($record[$columns[$i]]))
  133.                         .  '</' . $columns[$i] . '>' . $crlf;
  134.             }
  135.         }
  136.         $buffer         .= '    </' . $table . '>' . $crlf;
  137.         
  138.         if (!PMA_exportOutputHandler($buffer)) return FALSE;
  139.     }
  140.     mysql_free_result($result);
  141.  
  142.     return TRUE;
  143. } // end of the 'PMA_getTableXML()' function
  144. ?>