1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / SystemDatabase.class.php
blob93c2f74a4f32689da45cf3b598d73060246e3721
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA\SystemDatabase class
6 * @package PMA
7 */
9 namespace PMA;
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 require_once 'libraries/database_interface.inc.php';
17 /**
18 * Class SystemDatabase
20 * @package PMA
22 class SystemDatabase
24 /**
25 * @var \PMA_DatabaseInterface
27 protected $dbi;
29 /**
30 * Get instance of SystemDatabase
32 * @param \PMA_DatabaseInterface $dbi Database interface for the system database
35 function __construct(\PMA_DatabaseInterface $dbi)
37 $this->dbi = $dbi;
40 /**
41 * Get existing data on transformations applied for
42 * columns in a particular table
44 * @param string $db Database name looking for
46 * @return \mysqli_result Result of executed SQL query
48 public function getExistingTransformationData($db)
50 $cfgRelation = \PMA_getRelationsParam();
52 // Get the existing transformation details of the same database
53 // from pma__column_info table
54 $pma_transformation_sql = sprintf(
55 "SELECT * FROM %s.%s WHERE `db_name` = '%s'",
56 \PMA_Util::backquote($cfgRelation['db']),
57 \PMA_Util::backquote($cfgRelation['column_info']),
58 \PMA_Util::sqlAddSlashes($db)
61 return $this->dbi->tryQuery($pma_transformation_sql);
64 /**
65 * Get SQL query for store new transformation details of a VIEW
67 * @param object $pma_transformation_data Result set of SQL execution
68 * @param array $column_map Details of VIEW columns
69 * @param string $view_name Name of the VIEW
70 * @param string $db Database name of the VIEW
72 * @return string $new_transformations_sql SQL query for new transformations
74 function getNewTransformationDataSql(
75 $pma_transformation_data, $column_map, $view_name, $db
76 ) {
77 $cfgRelation = \PMA_getRelationsParam();
79 // Need to store new transformation details for VIEW
80 $new_transformations_sql = sprintf(
81 "INSERT INTO %s.%s ("
82 . "`db_name`, `table_name`, `column_name`, "
83 . "`comment`, `mimetype`, `transformation`, "
84 . "`transformation_options`) VALUES",
85 \PMA_Util::backquote($cfgRelation['db']),
86 \PMA_Util::backquote($cfgRelation['column_info'])
89 $column_count = 0;
90 $add_comma = false;
92 while ($data_row = $this->dbi->fetchAssoc($pma_transformation_data)) {
94 foreach ($column_map as $column) {
96 if ($data_row['table_name'] != $column['table_name']
97 || $data_row['column_name'] != $column['refering_column']
98 ) {
99 continue;
102 $new_transformations_sql .= sprintf(
103 "%s ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
104 $add_comma ? ', ' : '',
105 $db,
106 $view_name,
107 isset($column['real_column'])
108 ? $column['real_column']
109 : $column['refering_column'],
110 $data_row['comment'],
111 $data_row['mimetype'],
112 $data_row['transformation'],
113 \PMA_Util::sqlAddSlashes(
114 $data_row['transformation_options']
118 $add_comma = true;
119 $column_count++;
120 break;
123 if ($column_count == count($column_map)) {
124 break;
128 return ($column_count > 0) ? $new_transformations_sql : '';