1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 class JDatabaseExporterMysqli extends JDatabaseExporter
18 {
19 20 21 22 23 24 25 26
27 protected function buildXml()
28 {
29 $buffer = array();
30
31 $buffer[] = '<?xml version="1.0"?>';
32 $buffer[] = '<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
33 $buffer[] = ' <database name="">';
34
35 $buffer = array_merge($buffer, $this->buildXmlStructure());
36
37 $buffer[] = ' </database>';
38 $buffer[] = '</mysqldump>';
39
40 return implode("\n", $buffer);
41 }
42
43 44 45 46 47 48 49 50
51 protected function buildXmlStructure()
52 {
53 $buffer = array();
54
55 foreach ($this->from as $table)
56 {
57
58 $table = $this->getGenericTableName($table);
59
60
61 $fields = $this->db->getTableColumns($table, false);
62 $keys = $this->db->getTableKeys($table);
63
64 $buffer[] = ' <table_structure name="' . $table . '">';
65
66 foreach ($fields as $field)
67 {
68 $buffer[] = ' <field Field="' . $field->Field . '"' . ' Type="' . $field->Type . '"' . ' Null="' . $field->Null . '"' . ' Key="' .
69 $field->Key . '"' . (isset($field->Default) ? ' Default="' . $field->Default . '"' : '') . ' Extra="' . $field->Extra . '"' .
70 ' />';
71 }
72
73 foreach ($keys as $key)
74 {
75 $buffer[] = ' <key Table="' . $table . '"' . ' Non_unique="' . $key->Non_unique . '"' . ' Key_name="' . $key->Key_name . '"' .
76 ' Seq_in_index="' . $key->Seq_in_index . '"' . ' Column_name="' . $key->Column_name . '"' . ' Collation="' . $key->Collation . '"' .
77 ' Null="' . $key->Null . '"' . ' Index_type="' . $key->Index_type . '"' .
78 ' Comment="' . htmlspecialchars($key->Comment, ENT_COMPAT, 'UTF-8') . '"' . ' />';
79 }
80
81 $buffer[] = ' </table_structure>';
82 }
83
84 return $buffer;
85 }
86
87 88 89 90 91 92 93 94
95 public function check()
96 {
97
98 if (!($this->db instanceof JDatabaseDriverMysqli))
99 {
100 throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
101 }
102
103
104 if (empty($this->from))
105 {
106 throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
107 }
108
109 return $this;
110 }
111 }
112