Source for file mysqli.php

Documentation is available at mysqli.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Database
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * MySQLi export driver.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Database
  17.  * @since       11.1
  18.  */
  19. {
  20.     /**
  21.      * Builds the XML data for the tables to export.
  22.      *
  23.      * @return  string  An XML string
  24.      *
  25.      * @since   11.1
  26.      * @throws  Exception if an error occurs.
  27.      */
  28.     protected function buildXml()
  29.     {
  30.         $buffer array();
  31.  
  32.         $buffer['<?xml version="1.0"?>';
  33.         $buffer['<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
  34.         $buffer[' <database name="">';
  35.  
  36.         $buffer array_merge($buffer$this->buildXmlStructure());
  37.  
  38.         $buffer[' </database>';
  39.         $buffer['</mysqldump>';
  40.  
  41.         return implode("\n"$buffer);
  42.     }
  43.  
  44.     /**
  45.      * Builds the XML structure to export.
  46.      *
  47.      * @return  array  An array of XML lines (strings).
  48.      *
  49.      * @since   11.1
  50.      * @throws  Exception if an error occurs.
  51.      */
  52.     protected function buildXmlStructure()
  53.     {
  54.         $buffer array();
  55.  
  56.         foreach ($this->from as $table)
  57.         {
  58.             // Replace the magic prefix if found.
  59.             $table $this->getGenericTableName($table);
  60.  
  61.             // Get the details columns information.
  62.             $fields $this->db->getTableColumns($tablefalse);
  63.             $keys $this->db->getTableKeys($table);
  64.  
  65.             $buffer['  <table_structure name="' $table '">';
  66.  
  67.             foreach ($fields as $field)
  68.             {
  69.                 $buffer['   <field Field="' $field->Field '"' ' Type="' $field->Type '"' ' Null="' $field->Null '"' ' Key="' .
  70.                     $field->Key '"' (isset($field->Default' Default="' $field->Default '"' ''' Extra="' $field->Extra '"' .
  71.                     ' />';
  72.             }
  73.  
  74.             foreach ($keys as $key)
  75.             {
  76.                 $buffer['   <key Table="' $table '"' ' Non_unique="' $key->Non_unique '"' ' Key_name="' $key->Key_name '"' .
  77.                     ' Seq_in_index="' $key->Seq_in_index '"' ' Column_name="' $key->Column_name '"' ' Collation="' $key->Collation '"' .
  78.                     ' Null="' $key->Null '"' ' Index_type="' $key->Index_type '"' ' Comment="' htmlspecialchars($key->Comment'"' .
  79.                     ' />';
  80.             }
  81.  
  82.             $buffer['  </table_structure>';
  83.         }
  84.  
  85.         return $buffer;
  86.     }
  87.  
  88.     /**
  89.      * Checks if all data and options are in order prior to exporting.
  90.      *
  91.      * @return  JDatabaseExporterMysqli  Method supports chaining.
  92.      *
  93.      * @since   11.1
  94.      * @throws  Exception if an error is encountered.
  95.      */
  96.     public function check()
  97.     {
  98.         // Check if the db connector has been set.
  99.         if (!($this->db instanceof JDatabaseDriverMysqli))
  100.         {
  101.             throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
  102.         }
  103.  
  104.         // Check if the tables have been specified.
  105.         if (empty($this->from))
  106.         {
  107.             throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
  108.         }
  109.  
  110.         return $this;
  111.     }
  112. }

Documentation generated on Tue, 19 Nov 2013 15:09:13 +0100 by phpDocumentor 1.4.3