Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
mysqli.php
Aller à la documentation de ce fichier.
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  */
20 {
21  /**
22  * Builds the XML data for the tables to export.
23  *
24  * @return string An XML string
25  *
26  * @since 11.1
27  * @throws Exception if an error occurs.
28  */
29  protected function buildXml()
30  {
31  $buffer = array();
32 
33  $buffer[] = '<?xml version="1.0"?>';
34  $buffer[] = '<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
35  $buffer[] = ' <database name="">';
36 
37  $buffer = array_merge($buffer, $this->buildXmlStructure());
38 
39  $buffer[] = ' </database>';
40  $buffer[] = '</mysqldump>';
41 
42  return implode("\n", $buffer);
43  }
44 
45  /**
46  * Builds the XML structure to export.
47  *
48  * @return array An array of XML lines (strings).
49  *
50  * @since 11.1
51  * @throws Exception if an error occurs.
52  */
53  protected function buildXmlStructure()
54  {
55  $buffer = array();
56 
57  foreach ($this->from as $table)
58  {
59  // Replace the magic prefix if found.
60  $table = $this->getGenericTableName($table);
61 
62  // Get the details columns information.
63  $fields = $this->db->getTableColumns($table, false);
64  $keys = $this->db->getTableKeys($table);
65 
66  $buffer[] = ' <table_structure name="' . $table . '">';
67 
68  foreach ($fields as $field)
69  {
70  $buffer[] = ' <field Field="' . $field->Field . '"' . ' Type="' . $field->Type . '"' . ' Null="' . $field->Null . '"' . ' Key="' .
71  $field->Key . '"' . (isset($field->Default) ? ' Default="' . $field->Default . '"' : '') . ' Extra="' . $field->Extra . '"' .
72  ' />';
73  }
74 
75  foreach ($keys as $key)
76  {
77  $buffer[] = ' <key Table="' . $table . '"' . ' Non_unique="' . $key->Non_unique . '"' . ' Key_name="' . $key->Key_name . '"' .
78  ' Seq_in_index="' . $key->Seq_in_index . '"' . ' Column_name="' . $key->Column_name . '"' . ' Collation="' . $key->Collation . '"' .
79  ' Null="' . $key->Null . '"' . ' Index_type="' . $key->Index_type . '"' . ' Comment="' . htmlspecialchars($key->Comment) . '"' .
80  ' />';
81  }
82 
83  $buffer[] = ' </table_structure>';
84  }
85 
86  return $buffer;
87  }
88 
89  /**
90  * Checks if all data and options are in order prior to exporting.
91  *
92  * @return JDatabaseExporterMysqli Method supports chaining.
93  *
94  * @since 11.1
95  * @throws Exception if an error is encountered.
96  */
97  public function check()
98  {
99  // Check if the db connector has been set.
100  if (!($this->db instanceof JDatabaseDriverMysqli))
101  {
102  throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
103  }
104 
105  // Check if the tables have been specified.
106  if (empty($this->from))
107  {
108  throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
109  }
110 
111  return $this;
112  }
113 }