2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common Option Constants For DBI Functions
9 if (! defined('PHPMYADMIN')) {
16 // PMA_DBI_try_query()
17 define('PMA_DBI_QUERY_STORE', 1); // Force STORE_RESULT method, ignored by classic MySQL.
18 define('PMA_DBI_QUERY_UNBUFFERED', 2); // Do not read whole query
19 // PMA_DBI_get_variable()
20 define('PMA_DBI_GETVAR_SESSION', 1);
21 define('PMA_DBI_GETVAR_GLOBAL', 2);
24 * Checks one of the mysql extensions
26 * @param string $extension mysql extension to check
28 function PMA_DBI_checkMysqlExtension($extension = 'mysql') {
29 if (! function_exists($extension . '_connect')) {
37 * check for requested extension
39 if (! PMA_DBI_checkMysqlExtension($GLOBALS['cfg']['Server']['extension'])) {
41 // if it fails try alternative extension ...
42 // and display an error ...
45 * @todo add different messages for alternative extension
46 * and complete fail (no alternative extension too)
49 sprintf(PMA_sanitize($GLOBALS['strCantLoad']),
50 $GLOBALS['cfg']['Server']['extension'])
51 .' - <a href="./Documentation.html#faqmysql" target="documentation">'
52 .$GLOBALS['strDocu'] . '</a>';
53 trigger_error($error, E_USER_ERROR
);
55 if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') {
56 $alternativ_extension = 'mysqli';
58 $alternativ_extension = 'mysql';
61 if (! PMA_DBI_checkMysqlExtension($alternativ_extension)) {
62 // if alternative fails too ...
64 sprintf($GLOBALS['strCantLoad'],
65 $GLOBALS['cfg']['Server']['extension'])
66 . ' - [a@./Documentation.html#faqmysql@documentation]'
67 . $GLOBALS['strDocu'] . '[/a]');
70 $GLOBALS['cfg']['Server']['extension'] = $alternativ_extension;
71 unset($alternativ_extension);
75 * Including The DBI Plugin
77 require_once './libraries/dbi/' . $GLOBALS['cfg']['Server']['extension'] . '.dbi.lib.php';
82 function PMA_DBI_query($query, $link = null, $options = 0) {
83 $res = PMA_DBI_try_query($query, $link, $options)
84 or PMA_mysqlDie(PMA_DBI_getError($link), $query);
89 * converts charset of a mysql message, usually coming from mysql_error(),
90 * into PMA charset, usally UTF-8
91 * uses language to charset mapping from mysql/share/errmsg.txt
92 * and charset names to ISO charset from information_schema.CHARACTER_SETS
94 * @uses $GLOBALS['cfg']['IconvExtraParams']
95 * @uses $GLOBALS['charset'] as target charset
96 * @uses PMA_DBI_fetch_value() to get server_language
97 * @uses preg_match() to filter server_language
99 * @uses function_exists() to check for a convert function
100 * @uses iconv() to convert message
101 * @uses libiconv() to convert message
102 * @uses recode_string() to convert message
103 * @uses mb_convert_encoding() to convert message
104 * @param string $message
105 * @return string $message
107 function PMA_DBI_convert_message($message) {
108 // latin always last!
110 'japanese' => 'EUC-JP', //'ujis',
111 'japanese-sjis' => 'Shift-JIS', //'sjis',
112 'korean' => 'EUC-KR', //'euckr',
113 'russian' => 'KOI8-R', //'koi8r',
114 'ukrainian' => 'KOI8-U', //'koi8u',
115 'greek' => 'ISO-8859-7', //'greek',
116 'serbian' => 'CP1250', //'cp1250',
117 'estonian' => 'ISO-8859-13', //'latin7',
118 'slovak' => 'ISO-8859-2', //'latin2',
119 'czech' => 'ISO-8859-2', //'latin2',
120 'hungarian' => 'ISO-8859-2', //'latin2',
121 'polish' => 'ISO-8859-2', //'latin2',
122 'romanian' => 'ISO-8859-2', //'latin2',
123 'spanish' => 'CP1252', //'latin1',
124 'swedish' => 'CP1252', //'latin1',
125 'italian' => 'CP1252', //'latin1',
126 'norwegian-ny' => 'CP1252', //'latin1',
127 'norwegian' => 'CP1252', //'latin1',
128 'portuguese' => 'CP1252', //'latin1',
129 'danish' => 'CP1252', //'latin1',
130 'dutch' => 'CP1252', //'latin1',
131 'english' => 'CP1252', //'latin1',
132 'french' => 'CP1252', //'latin1',
133 'german' => 'CP1252', //'latin1',
136 if ($server_language = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'language\';', 0, 1)) {
138 if (preg_match('&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', $server_language, $found)) {
139 $server_language = $found[1];
143 if (! empty($server_language) && isset($encodings[$server_language])) {
144 if (function_exists('iconv')) {
145 if ((@stristr
(PHP_OS
, 'AIX')) && (@strcasecmp
(ICONV_IMPL
, 'unknown') == 0) && (@strcasecmp
(ICONV_VERSION
, 'unknown') == 0)) {
146 require_once './libraries/iconv_wrapper.lib.php';
147 $message = PMA_aix_iconv_wrapper($encodings[$server_language],
148 $GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
150 $message = iconv($encodings[$server_language],
151 $GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
153 } elseif (function_exists('recode_string')) {
154 $message = recode_string($encodings[$server_language] . '..' . $GLOBALS['charset'],
156 } elseif (function_exists('libiconv')) {
157 $message = libiconv($encodings[$server_language], $GLOBALS['charset'], $message);
158 } elseif (function_exists('mb_convert_encoding')) {
159 // do not try unsupported charsets
160 if (! in_array($server_language, array('ukrainian', 'greek', 'serbian'))) {
161 $message = mb_convert_encoding($message, $GLOBALS['charset'],
162 $encodings[$server_language]);
167 * @todo lang not found, try all, what TODO ?
175 * returns array with table names for given db
177 * @param string $database name of database
178 * @param mixed $link mysql link resource|object
179 * @return array tables names
181 function PMA_DBI_get_tables($database, $link = null)
183 return PMA_DBI_fetch_result('SHOW TABLES FROM ' . PMA_backquote($database) . ';',
184 null, 0, $link, PMA_DBI_QUERY_STORE
);
188 * usort comparison callback
190 * @param string $a first argument to sort
191 * @param string $b second argument to sort
193 * @return integer a value representing whether $a should be before $b in the
194 * sorted array or not
196 * @global string the column the array shall be sorted by
197 * @global string the sorting order ('ASC' or 'DESC')
201 function PMA_usort_comparison_callback($a, $b)
203 if ($GLOBALS['cfg']['NaturalOrder']) {
204 $sorter = 'strnatcasecmp';
206 $sorter = 'strcasecmp';
209 // return -1 * strnatcasecmp($a["SCHEMA_TABLES"], $b["SCHEMA_TABLES"])
210 return ($GLOBALS['callback_sort_order'] == 'ASC' ?
1 : -1) * $sorter($a[$GLOBALS['callback_sort_by']], $b[$GLOBALS['callback_sort_by']]);
211 } // end of the 'PMA_usort_comparison_callback()' function
214 * returns array of all tables in given db or dbs
215 * this function expects unquoted names:
217 * WRONG: `my_database`
218 * WRONG: my\_database
219 * if $tbl_is_group is true, $table is used as filter for table names
220 * if $tbl_is_group is 'comment, $table is used as filter for table comments
223 * PMA_DBI_get_tables_full('my_database');
224 * PMA_DBI_get_tables_full('my_database', 'my_table'));
225 * PMA_DBI_get_tables_full('my_database', 'my_tables_', true));
226 * PMA_DBI_get_tables_full('my_database', 'my_tables_', 'comment'));
229 * @todo move into PMA_Table
230 * @uses PMA_DBI_fetch_result()
231 * @uses PMA_escape_mysql_wildcards()
232 * @uses PMA_backquote()
237 * @param string $databases database
238 * @param string $table table
239 * @param boolean|string $tbl_is_group $table is a table group
240 * @param resource $link mysql link
241 * @param integer $limit_offset zero-based offset for the count
242 * @param boolean|integer $limit_count number of tables to return
243 * @param string $sort_by table attribute to sort by
244 * @param string $sort_order direction to sort (ASC or DESC)
245 * @return array list of tables in given db(s)
247 function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = false, $link = null,
248 $limit_offset = 0, $limit_count = false, $sort_by = 'Name', $sort_order = 'ASC')
250 require_once './libraries/Table.class.php';
252 if (true === $limit_count) {
253 $limit_count = $GLOBALS['cfg']['MaxTableList'];
255 // prepare and check parameters
256 if (! is_array($database)) {
257 $databases = array($database);
259 $databases = $database;
264 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
265 // get table information from information_schema
267 if (true === $tbl_is_group) {
268 $sql_where_table = 'AND `TABLE_NAME` LIKE \''
269 . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
270 } elseif ('comment' === $tbl_is_group) {
271 $sql_where_table = 'AND `TABLE_COMMENT` LIKE \''
272 . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
274 $sql_where_table = 'AND `TABLE_NAME` = \'' . addslashes($table) . '\'';
277 $sql_where_table = '';
281 // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME`
283 // on non-Windows servers,
284 // added BINARY in the WHERE clause to force a case sensitive
285 // comparison (if we are looking for the db Aa we don't want
286 // to find the db aa)
287 $this_databases = array_map('PMA_sqlAddslashes', $databases);
291 `TABLE_SCHEMA` AS `Db`,
292 `TABLE_NAME` AS `Name`,
293 `ENGINE` AS `Engine`,
295 `VERSION` AS `Version`,
296 `ROW_FORMAT` AS `Row_format`,
297 `TABLE_ROWS` AS `Rows`,
298 `AVG_ROW_LENGTH` AS `Avg_row_length`,
299 `DATA_LENGTH` AS `Data_length`,
300 `MAX_DATA_LENGTH` AS `Max_data_length`,
301 `INDEX_LENGTH` AS `Index_length`,
302 `DATA_FREE` AS `Data_free`,
303 `AUTO_INCREMENT` AS `Auto_increment`,
304 `CREATE_TIME` AS `Create_time`,
305 `UPDATE_TIME` AS `Update_time`,
306 `CHECK_TIME` AS `Check_time`,
307 `TABLE_COLLATION` AS `Collation`,
308 `CHECKSUM` AS `Checksum`,
309 `CREATE_OPTIONS` AS `Create_options`,
310 `TABLE_COMMENT` AS `Comment`
311 FROM `information_schema`.`TABLES`
312 WHERE ' . (PMA_IS_WINDOWS ?
'' : 'BINARY') . ' `TABLE_SCHEMA` IN (\'' . implode("', '", $this_databases) . '\')
313 ' . $sql_where_table;
316 if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) {
317 // This crazy bit of SQL was inspired by a post here:
318 // http://forums.mysql.com/read.php?10,34908,35959#msg-35959
320 // Find the longest table name
321 $max_name_sql = "SELECT MAX(LENGTH(TABLE_NAME)) FROM `information_schema`.`TABLES`
322 WHERE `TABLE_SCHEMA` IN ('" . implode("', '", $this_databases) . "')";
323 $max_name_array = PMA_DBI_fetch_result($max_name_sql);
324 $max_name_length = $max_name_array[0];
326 // Put the CASE statement SQL together.
328 for ($i = 1; $i < $max_name_length; $i++
) {
329 $sql_case .= " when substr(Name, $i) between '0' and '9' then $i";
331 $sql_case .= " ELSE $max_name_length end) ";
333 // Add the CASE statement to the main SQL
334 $sql .= " ORDER BY left(Name, (CASE ";
335 $sql .= $sql_case . "-1) $sort_order, 0+substr(Name, CASE";
336 $sql .= $sql_case . $sort_order;
338 // Just let MySQL sort as it normally does
339 $sql .= " ORDER BY $sort_by $sort_order";
343 $sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset;
346 $tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA', 'TABLE_NAME'),
348 unset($sql_where_table, $sql);
351 // If permissions are wrong on even one database directory,
352 // information_schema does not return any table info for any database
353 // this is why we fall back to SHOW TABLE STATUS even for MySQL >= 50002
354 if (empty($tables)) {
355 foreach ($databases as $each_database) {
356 if ($table ||
(true === $tbl_is_group)) {
357 $sql = 'SHOW TABLE STATUS FROM '
358 . PMA_backquote($each_database)
359 .' LIKE \'' . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
361 $sql = 'SHOW TABLE STATUS FROM '
362 . PMA_backquote($each_database);
365 $each_tables = PMA_DBI_fetch_result($sql, 'Name', null, $link);
367 // Sort naturally if the config allows it and we're sorting
369 if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) {
370 uksort($each_tables, 'strnatcasecmp');
372 if ($sort_order == 'DESC') {
373 $each_tables = array_reverse($each_tables);
376 // Prepare to sort by creating array of the selected sort
377 // value to pass to array_multisort
378 foreach ($each_tables as $table_name => $table_data) {
379 $
{$sort_by}[$table_name] = strtolower($table_data[$sort_by]);
382 if ($sort_order == 'DESC') {
383 array_multisort($
$sort_by, SORT_DESC
, $each_tables);
385 array_multisort($
$sort_by, SORT_ASC
, $each_tables);
388 // cleanup the temporary sort array
393 $each_tables = array_slice($each_tables, $limit_offset, $limit_count);
396 foreach ($each_tables as $table_name => $each_table) {
397 if ('comment' === $tbl_is_group
398 && 0 === strpos($each_table['Comment'], $table))
400 // remove table from list
401 unset($each_tables[$table_name]);
405 if (! isset($each_tables[$table_name]['Type'])
406 && isset($each_tables[$table_name]['Engine'])) {
407 // pma BC, same parts of PMA still uses 'Type'
408 $each_tables[$table_name]['Type']
409 =& $each_tables[$table_name]['Engine'];
410 } elseif (! isset($each_tables[$table_name]['Engine'])
411 && isset($each_tables[$table_name]['Type'])) {
412 // old MySQL reports Type, newer MySQL reports Engine
413 $each_tables[$table_name]['Engine']
414 =& $each_tables[$table_name]['Type'];
417 // MySQL forward compatibility
418 // so pma could use this array as if every server is of version >5.0
419 $each_tables[$table_name]['TABLE_SCHEMA'] = $each_database;
420 $each_tables[$table_name]['TABLE_NAME'] =& $each_tables[$table_name]['Name'];
421 $each_tables[$table_name]['ENGINE'] =& $each_tables[$table_name]['Engine'];
422 $each_tables[$table_name]['VERSION'] =& $each_tables[$table_name]['Version'];
423 $each_tables[$table_name]['ROW_FORMAT'] =& $each_tables[$table_name]['Row_format'];
424 $each_tables[$table_name]['TABLE_ROWS'] =& $each_tables[$table_name]['Rows'];
425 $each_tables[$table_name]['AVG_ROW_LENGTH'] =& $each_tables[$table_name]['Avg_row_length'];
426 $each_tables[$table_name]['DATA_LENGTH'] =& $each_tables[$table_name]['Data_length'];
427 $each_tables[$table_name]['MAX_DATA_LENGTH'] =& $each_tables[$table_name]['Max_data_length'];
428 $each_tables[$table_name]['INDEX_LENGTH'] =& $each_tables[$table_name]['Index_length'];
429 $each_tables[$table_name]['DATA_FREE'] =& $each_tables[$table_name]['Data_free'];
430 $each_tables[$table_name]['AUTO_INCREMENT'] =& $each_tables[$table_name]['Auto_increment'];
431 $each_tables[$table_name]['CREATE_TIME'] =& $each_tables[$table_name]['Create_time'];
432 $each_tables[$table_name]['UPDATE_TIME'] =& $each_tables[$table_name]['Update_time'];
433 $each_tables[$table_name]['CHECK_TIME'] =& $each_tables[$table_name]['Check_time'];
434 $each_tables[$table_name]['TABLE_COLLATION'] =& $each_tables[$table_name]['Collation'];
435 $each_tables[$table_name]['CHECKSUM'] =& $each_tables[$table_name]['Checksum'];
436 $each_tables[$table_name]['CREATE_OPTIONS'] =& $each_tables[$table_name]['Create_options'];
437 $each_tables[$table_name]['TABLE_COMMENT'] =& $each_tables[$table_name]['Comment'];
439 if (strtoupper($each_tables[$table_name]['Comment']) === 'VIEW'
440 && $each_tables[$table_name]['Engine'] == NULL) {
441 $each_tables[$table_name]['TABLE_TYPE'] = 'VIEW';
444 * @todo difference between 'TEMPORARY' and 'BASE TABLE' but how to detect?
446 $each_tables[$table_name]['TABLE_TYPE'] = 'BASE TABLE';
450 $tables[$each_database] = $each_tables;
455 // so PMA_Table does not require to issue SHOW TABLE STATUS again
456 // Note: I don't see why we would need array_merge_recursive() here,
457 // as it creates double entries for the same table (for example a double
458 // entry for Comment when changing the storage engine in Operations)
459 // Note 2: Instead of array_merge(), simply use the + operator because
460 // array_merge() renumbers numeric keys starting with 0, therefore
461 // we would lose a db name thats consists only of numbers
462 PMA_Table
::$cache = PMA_Table
::$cache +
$tables;
464 if (! is_array($database)) {
465 if (isset($tables[$database])) {
466 return $tables[$database];
467 } elseif (isset($tables[strtolower($database)])) {
468 // on windows with lower_case_table_names = 1
470 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
471 // but information_schema.TABLES gives `test`
473 // http://sf.net/support/tracker.php?aid=1436171
474 return $tables[strtolower($database)];
484 * returns array with databases containing extended infos about them
486 * @todo move into PMA_List_Database?
487 * @param string $databases database
488 * @param boolean $force_stats retrieve stats also for MySQL < 5
489 * @param resource $link mysql link
490 * @param string $sort_by column to order by
491 * @param string $sort_order ASC or DESC
492 * @param integer $limit_offset starting offset for LIMIT
493 * @param bool|int $limit_count row count for LIMIT or true for $GLOBALS['cfg']['MaxDbList']
494 * @return array $databases
496 function PMA_DBI_get_databases_full($database = null, $force_stats = false,
497 $link = null, $sort_by = 'SCHEMA_NAME', $sort_order = 'ASC',
498 $limit_offset = 0, $limit_count = false)
500 $sort_order = strtoupper($sort_order);
502 if (true === $limit_count) {
503 $limit_count = $GLOBALS['cfg']['MaxDbList'];
506 // initialize to avoid errors when there are no databases
507 $databases = array();
509 $apply_limit_and_order_manual = true;
511 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
513 * if $GLOBALS['cfg']['NaturalOrder'] is enabled, we cannot use LIMIT
514 * cause MySQL does not support natural ordering, we have to do it afterward
516 if ($GLOBALS['cfg']['NaturalOrder']) {
520 $limit = ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset;
523 $apply_limit_and_order_manual = false;
526 // get table information from information_schema
528 $sql_where_schema = 'WHERE `SCHEMA_NAME` LIKE \''
529 . addslashes($database) . '\'';
531 $sql_where_schema = '';
535 // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME`
537 SELECT `information_schema`.`SCHEMATA`.*';
540 COUNT(`information_schema`.`TABLES`.`TABLE_SCHEMA`)
542 SUM(`information_schema`.`TABLES`.`TABLE_ROWS`)
543 AS `SCHEMA_TABLE_ROWS`,
544 SUM(`information_schema`.`TABLES`.`DATA_LENGTH`)
545 AS `SCHEMA_DATA_LENGTH`,
546 SUM(`information_schema`.`TABLES`.`MAX_DATA_LENGTH`)
547 AS `SCHEMA_MAX_DATA_LENGTH`,
548 SUM(`information_schema`.`TABLES`.`INDEX_LENGTH`)
549 AS `SCHEMA_INDEX_LENGTH`,
550 SUM(`information_schema`.`TABLES`.`DATA_LENGTH`
551 + `information_schema`.`TABLES`.`INDEX_LENGTH`)
553 SUM(`information_schema`.`TABLES`.`DATA_FREE`)
554 AS `SCHEMA_DATA_FREE`';
557 FROM `information_schema`.`SCHEMATA`';
560 LEFT JOIN `information_schema`.`TABLES`
561 ON BINARY `information_schema`.`TABLES`.`TABLE_SCHEMA`
562 = BINARY `information_schema`.`SCHEMATA`.`SCHEMA_NAME`';
565 ' . $sql_where_schema . '
566 GROUP BY BINARY `information_schema`.`SCHEMATA`.`SCHEMA_NAME`
567 ORDER BY BINARY ' . PMA_backquote($sort_by) . ' ' . $sort_order
569 $databases = PMA_DBI_fetch_result($sql, 'SCHEMA_NAME', null, $link);
571 $mysql_error = PMA_DBI_getError($link);
572 if (! count($databases) && $GLOBALS['errno']) {
573 PMA_mysqlDie($mysql_error, $sql);
576 // display only databases also in official database list
577 // f.e. to apply hide_db and only_db
578 $drops = array_diff(array_keys($databases), (array) $GLOBALS['pma']->databases
);
580 foreach ($drops as $drop) {
581 unset($databases[$drop]);
585 unset($sql_where_schema, $sql, $drops);
587 foreach ($GLOBALS['pma']->databases
as $database_name) {
588 // MySQL forward compatibility
589 // so pma could use this array as if every server is of version >5.0
590 $databases[$database_name]['SCHEMA_NAME'] = $database_name;
593 require_once './libraries/mysql_charsets.lib.php';
595 $databases[$database_name]['DEFAULT_COLLATION_NAME']
596 = PMA_getDbCollation($database_name);
598 // get additional info about tables
599 $databases[$database_name]['SCHEMA_TABLES'] = 0;
600 $databases[$database_name]['SCHEMA_TABLE_ROWS'] = 0;
601 $databases[$database_name]['SCHEMA_DATA_LENGTH'] = 0;
602 $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] = 0;
603 $databases[$database_name]['SCHEMA_INDEX_LENGTH'] = 0;
604 $databases[$database_name]['SCHEMA_LENGTH'] = 0;
605 $databases[$database_name]['SCHEMA_DATA_FREE'] = 0;
607 $res = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($database_name) . ';');
608 while ($row = PMA_DBI_fetch_assoc($res)) {
609 $databases[$database_name]['SCHEMA_TABLES']++
;
610 $databases[$database_name]['SCHEMA_TABLE_ROWS']
612 $databases[$database_name]['SCHEMA_DATA_LENGTH']
613 +
= $row['Data_length'];
614 $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH']
615 +
= $row['Max_data_length'];
616 $databases[$database_name]['SCHEMA_INDEX_LENGTH']
617 +
= $row['Index_length'];
619 // for InnoDB, this does not contain the number of
620 // overhead bytes but the total free space
621 if ('InnoDB' != $row['Engine']) {
622 $databases[$database_name]['SCHEMA_DATA_FREE']
623 +
= $row['Data_free'];
625 $databases[$database_name]['SCHEMA_LENGTH']
626 +
= $row['Data_length'] +
$row['Index_length'];
628 PMA_DBI_free_result($res);
636 * apply limit and order manually now
637 * (caused by older MySQL < 5 or $GLOBALS['cfg']['NaturalOrder'])
639 if ($apply_limit_and_order_manual) {
640 $GLOBALS['callback_sort_order'] = $sort_order;
641 $GLOBALS['callback_sort_by'] = $sort_by;
642 usort($databases, 'PMA_usort_comparison_callback');
643 unset($GLOBALS['callback_sort_order'], $GLOBALS['callback_sort_by']);
649 $databases = array_slice($databases, $limit_offset, $limit_count);
657 * returns detailed array with all columns for given table in database,
658 * or all tables/databases
660 * @param string $database name of database
661 * @param string $table name of table to retrieve columns from
662 * @param string $column name of specific column
663 * @param mixed $link mysql link resource
665 function PMA_DBI_get_columns_full($database = null, $table = null,
666 $column = null, $link = null)
670 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
671 $sql_wheres = array();
672 $array_keys = array();
674 // get columns information from information_schema
675 if (null !== $database) {
676 $sql_wheres[] = '`TABLE_SCHEMA` = \'' . addslashes($database) . '\' ';
678 $array_keys[] = 'TABLE_SCHEMA';
680 if (null !== $table) {
681 $sql_wheres[] = '`TABLE_NAME` = \'' . addslashes($table) . '\' ';
683 $array_keys[] = 'TABLE_NAME';
685 if (null !== $column) {
686 $sql_wheres[] = '`COLUMN_NAME` = \'' . addslashes($column) . '\' ';
688 $array_keys[] = 'COLUMN_NAME';
692 // `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]`
695 `COLUMN_NAME` AS `Field`,
696 `COLUMN_TYPE` AS `Type`,
697 `COLLATION_NAME` AS `Collation`,
698 `IS_NULLABLE` AS `Null`,
699 `COLUMN_KEY` AS `Key`,
700 `COLUMN_DEFAULT` AS `Default`,
702 `PRIVILEGES` AS `Privileges`,
703 `COLUMN_COMMENT` AS `Comment`
704 FROM `information_schema`.`COLUMNS`';
705 if (count($sql_wheres)) {
706 $sql .= "\n" . ' WHERE ' . implode(' AND ', $sql_wheres);
709 $columns = PMA_DBI_fetch_result($sql, $array_keys, null, $link);
710 unset($sql_wheres, $sql);
712 if (null === $database) {
713 foreach ($GLOBALS['pma']->databases
as $database) {
714 $columns[$database] = PMA_DBI_get_columns_full($database, null,
718 } elseif (null === $table) {
719 $tables = PMA_DBI_get_tables($database);
720 foreach ($tables as $table) {
721 $columns[$table] = PMA_DBI_get_columns_full(
722 $database, $table, null, $link);
727 $sql = 'SHOW FULL COLUMNS FROM '
728 . PMA_backquote($database) . '.' . PMA_backquote($table);
729 if (null !== $column) {
730 $sql .= " LIKE '" . $column . "'";
733 $columns = PMA_DBI_fetch_result($sql, 'Field', null, $link);
735 $ordinal_position = 1;
736 foreach ($columns as $column_name => $each_column) {
738 // MySQL forward compatibility
739 // so pma could use this array as if every server is of version >5.0
740 $columns[$column_name]['COLUMN_NAME'] =& $columns[$column_name]['Field'];
741 $columns[$column_name]['COLUMN_TYPE'] =& $columns[$column_name]['Type'];
742 $columns[$column_name]['COLLATION_NAME'] =& $columns[$column_name]['Collation'];
743 $columns[$column_name]['IS_NULLABLE'] =& $columns[$column_name]['Null'];
744 $columns[$column_name]['COLUMN_KEY'] =& $columns[$column_name]['Key'];
745 $columns[$column_name]['COLUMN_DEFAULT'] =& $columns[$column_name]['Default'];
746 $columns[$column_name]['EXTRA'] =& $columns[$column_name]['Extra'];
747 $columns[$column_name]['PRIVILEGES'] =& $columns[$column_name]['Privileges'];
748 $columns[$column_name]['COLUMN_COMMENT'] =& $columns[$column_name]['Comment'];
750 $columns[$column_name]['TABLE_CATALOG'] = null;
751 $columns[$column_name]['TABLE_SCHEMA'] = $database;
752 $columns[$column_name]['TABLE_NAME'] = $table;
753 $columns[$column_name]['ORDINAL_POSITION'] = $ordinal_position;
754 $columns[$column_name]['DATA_TYPE'] =
755 substr($columns[$column_name]['COLUMN_TYPE'], 0,
756 strpos($columns[$column_name]['COLUMN_TYPE'], '('));
758 * @todo guess CHARACTER_MAXIMUM_LENGTH from COLUMN_TYPE
760 $columns[$column_name]['CHARACTER_MAXIMUM_LENGTH'] = null;
762 * @todo guess CHARACTER_OCTET_LENGTH from CHARACTER_MAXIMUM_LENGTH
764 $columns[$column_name]['CHARACTER_OCTET_LENGTH'] = null;
765 $columns[$column_name]['NUMERIC_PRECISION'] = null;
766 $columns[$column_name]['NUMERIC_SCALE'] = null;
767 $columns[$column_name]['CHARACTER_SET_NAME'] =
768 substr($columns[$column_name]['COLLATION_NAME'], 0,
769 strpos($columns[$column_name]['COLLATION_NAME'], '_'));
774 if (null !== $column) {
776 $columns = current($columns);
784 * @todo should only return columns names, for more info use PMA_DBI_get_columns_full()
786 * @deprecated by PMA_DBI_get_columns() or PMA_DBI_get_columns_full()
787 * @param string $database name of database
788 * @param string $table name of table to retrieve columns from
789 * @param mixed $link mysql link resource
790 * @return array column info
792 function PMA_DBI_get_fields($database, $table, $link = null)
794 // here we use a try_query because when coming from
795 // tbl_create + tbl_properties.inc.php, the table does not exist
796 $fields = PMA_DBI_fetch_result(
798 FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table),
800 if (! is_array($fields) ||
count($fields) < 1) {
807 * array PMA_DBI_get_columns(string $database, string $table, bool $full = false, mysql db link $link = null)
809 * @param string $database name of database
810 * @param string $table name of table to retrieve columns from
811 * @param boolean $full whether to return full info or only column names
812 * @param mixed $link mysql link resource
813 * @return array column names
815 function PMA_DBI_get_columns($database, $table, $full = false, $link = null)
817 $fields = PMA_DBI_fetch_result(
818 'SHOW ' . ($full ?
'FULL' : '') . ' COLUMNS
819 FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table),
820 'Field', ($full ?
null : 'Field'), $link);
821 if (! is_array($fields) ||
count($fields) < 1) {
828 * array PMA_DBI_get_column_values (string $database, string $table, string $column , mysql db link $link = null)
830 * @param string $database name of database
831 * @param string $table name of table to retrieve columns from
832 * @param string $column name of the column to retrieve data from
833 * @param mixed $link mysql link resource
834 * @return array $field_values
837 function PMA_DBI_get_column_values($database, $table, $column, $link = null)
840 for($i=0; $i< sizeof($column); $i++
)
842 $query.= PMA_backquote($column[$i]);
843 if($i < (sizeof($column)-1))
848 $query.= ' FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table);
849 $field_values = PMA_DBI_fetch_result($query, null, null, $link);
851 if (! is_array($field_values) ||
count($field_values) < 1) {
854 return $field_values;
857 * array PMA_DBI_get_table_data (string $database, string $table, mysql db link $link = null)
859 * @param string $database name of database
860 * @param string $table name of table to retrieve columns from
861 * @param mixed $link mysql link resource
862 * @return array $result
865 function PMA_DBI_get_table_data($database, $table, $link = null)
868 $result = PMA_DBI_fetch_result(
869 'SELECT * FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table),
872 if (! is_array($result) ||
count($result) < 1) {
879 * array PMA_DBI_get_table_indexes($database, $table, $link = null)
881 * @param string $database name of database
882 * @param string $table name of the table whose indexes are to be retreived
883 * @param mixed $link mysql link resource
884 * @return array $indexes
887 function PMA_DBI_get_table_indexes($database, $table, $link = null)
890 $indexes = PMA_DBI_fetch_result(
891 'SHOW INDEXES FROM ' .PMA_backquote($database) . '.' . PMA_backquote($table),
894 if (! is_array($indexes) ||
count($indexes) < 1) {
901 * returns value of given mysql server variable
903 * @param string $var mysql server variable name
904 * @param int $type PMA_DBI_GETVAR_SESSION|PMA_DBI_GETVAR_GLOBAL
905 * @param mixed $link mysql link resource|object
906 * @return mixed value for mysql server variable
910 function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION
, $link = null)
912 if ($link === null) {
913 if (isset($GLOBALS['userlink'])) {
914 $link = $GLOBALS['userlink'];
921 case PMA_DBI_GETVAR_SESSION
:
922 $modifier = ' SESSION';
924 case PMA_DBI_GETVAR_GLOBAL
:
925 $modifier = ' GLOBAL';
930 return PMA_DBI_fetch_value(
931 'SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 0, 1, $link);
935 * Function called just after a connection to the MySQL database server has been established
936 * It sets the connection collation, and determins the version of MySQL which is running.
938 * @uses ./libraries/charset_conversion.lib.php
939 * @uses PMA_DBI_QUERY_STORE
940 * @uses PMA_MYSQL_INT_VERSION to set it
941 * @uses PMA_MYSQL_STR_VERSION to set it
942 * @uses $_SESSION['PMA_MYSQL_INT_VERSION'] for caching
943 * @uses $_SESSION['PMA_MYSQL_STR_VERSION'] for caching
944 * @uses PMA_DBI_GETVAR_SESSION
945 * @uses PMA_DBI_fetch_value()
946 * @uses PMA_DBI_query()
947 * @uses PMA_DBI_get_variable()
948 * @uses $GLOBALS['collation_connection']
949 * @uses $GLOBALS['available_languages']
950 * @uses $GLOBALS['mysql_charset_map']
951 * @uses $GLOBALS['charset']
952 * @uses $GLOBALS['lang']
953 * @uses $GLOBALS['server']
954 * @uses $GLOBALS['cfg']['Lang']
963 * @param mixed $link mysql link resource|object
964 * @param boolean $is_controluser
966 function PMA_DBI_postConnect($link, $is_controluser = false)
968 if (! defined('PMA_MYSQL_INT_VERSION')) {
969 if (PMA_cacheExists('PMA_MYSQL_INT_VERSION', true)) {
970 define('PMA_MYSQL_INT_VERSION', PMA_cacheGet('PMA_MYSQL_INT_VERSION', true));
971 define('PMA_MYSQL_STR_VERSION', PMA_cacheGet('PMA_MYSQL_STR_VERSION', true));
973 $mysql_version = PMA_DBI_fetch_value(
974 'SELECT VERSION()', 0, 0, $link, PMA_DBI_QUERY_STORE
);
975 if ($mysql_version) {
976 $match = explode('.', $mysql_version);
977 define('PMA_MYSQL_INT_VERSION',
978 (int) sprintf('%d%02d%02d', $match[0], $match[1],
980 define('PMA_MYSQL_STR_VERSION', $mysql_version);
981 unset($mysql_version, $match);
983 define('PMA_MYSQL_INT_VERSION', 50015);
984 define('PMA_MYSQL_STR_VERSION', '5.00.15');
986 PMA_cacheSet('PMA_MYSQL_INT_VERSION', PMA_MYSQL_INT_VERSION
, true);
987 PMA_cacheSet('PMA_MYSQL_STR_VERSION', PMA_MYSQL_STR_VERSION
, true);
991 if (! empty($GLOBALS['collation_connection'])) {
992 PMA_DBI_query("SET CHARACTER SET 'utf8';", $link, PMA_DBI_QUERY_STORE
);
993 $mysql_charset = explode('_', $GLOBALS['collation_connection']);
994 PMA_DBI_query("SET collation_connection = '" . PMA_sqlAddslashes($GLOBALS['collation_connection']) . "';", $link, PMA_DBI_QUERY_STORE
);
996 PMA_DBI_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci';", $link, PMA_DBI_QUERY_STORE
);
1001 * returns a single value from the given result or query,
1002 * if the query or the result has more than one row or field
1003 * the first field of the first row is returned
1006 * $sql = 'SELECT `name` FROM `user` WHERE `id` = 123';
1007 * $user_name = PMA_DBI_fetch_value($sql);
1009 * // $user_name = 'John Doe'
1014 * @uses PMA_DBI_try_query()
1015 * @uses PMA_DBI_num_rows()
1016 * @uses PMA_DBI_fetch_row()
1017 * @uses PMA_DBI_fetch_assoc()
1018 * @uses PMA_DBI_free_result()
1019 * @param string|mysql_result $result query or mysql result
1020 * @param integer $row_number row to fetch the value from,
1021 * starting at 0, with 0 beeing default
1022 * @param integer|string $field field to fetch the value from,
1023 * starting at 0, with 0 beeing default
1024 * @param resource $link mysql link
1025 * @param mixed $options
1026 * @return mixed value of first field in first row from result
1027 * or false if not found
1029 function PMA_DBI_fetch_value($result, $row_number = 0, $field = 0, $link = null, $options = 0) {
1032 if (is_string($result)) {
1033 $result = PMA_DBI_try_query($result, $link, $options | PMA_DBI_QUERY_STORE
);
1036 // return false if result is empty or false
1037 // or requested row is larger than rows in result
1038 if (PMA_DBI_num_rows($result) < ($row_number +
1)) {
1042 // if $field is an integer use non associative mysql fetch function
1043 if (is_int($field)) {
1044 $fetch_function = 'PMA_DBI_fetch_row';
1046 $fetch_function = 'PMA_DBI_fetch_assoc';
1049 // get requested row
1050 for ($i = 0; $i <= $row_number; $i++
) {
1051 $row = $fetch_function($result);
1053 PMA_DBI_free_result($result);
1055 // return requested field
1056 if (isset($row[$field])) {
1057 $value = $row[$field];
1065 * returns only the first row from the result
1068 * $sql = 'SELECT * FROM `user` WHERE `id` = 123';
1069 * $user = PMA_DBI_fetch_single_row($sql);
1071 * // $user = array('id' => 123, 'name' => 'John Doe')
1075 * @uses PMA_DBI_try_query()
1076 * @uses PMA_DBI_num_rows()
1077 * @uses PMA_DBI_fetch_row()
1078 * @uses PMA_DBI_fetch_assoc()
1079 * @uses PMA_DBI_fetch_array()
1080 * @uses PMA_DBI_free_result()
1081 * @param string|mysql_result $result query or mysql result
1082 * @param string $type NUM|ASSOC|BOTH
1083 * returned array should either numeric
1084 * associativ or booth
1085 * @param resource $link mysql link
1086 * @param mixed $options
1087 * @return array|boolean first row from result
1088 * or false if result is empty
1090 function PMA_DBI_fetch_single_row($result, $type = 'ASSOC', $link = null, $options = 0) {
1091 if (is_string($result)) {
1092 $result = PMA_DBI_try_query($result, $link, $options | PMA_DBI_QUERY_STORE
);
1095 // return null if result is empty or false
1096 if (! PMA_DBI_num_rows($result)) {
1102 $fetch_function = 'PMA_DBI_fetch_row';
1105 $fetch_function = 'PMA_DBI_fetch_assoc';
1109 $fetch_function = 'PMA_DBI_fetch_array';
1113 $row = $fetch_function($result);
1114 PMA_DBI_free_result($result);
1119 * returns all rows in the resultset in one array
1122 * $sql = 'SELECT * FROM `user`';
1123 * $users = PMA_DBI_fetch_result($sql);
1125 * // $users[] = array('id' => 123, 'name' => 'John Doe')
1127 * $sql = 'SELECT `id`, `name` FROM `user`';
1128 * $users = PMA_DBI_fetch_result($sql, 'id');
1130 * // $users['123'] = array('id' => 123, 'name' => 'John Doe')
1132 * $sql = 'SELECT `id`, `name` FROM `user`';
1133 * $users = PMA_DBI_fetch_result($sql, 0);
1135 * // $users['123'] = array(0 => 123, 1 => 'John Doe')
1137 * $sql = 'SELECT `id`, `name` FROM `user`';
1138 * $users = PMA_DBI_fetch_result($sql, 'id', 'name');
1140 * $users = PMA_DBI_fetch_result($sql, 0, 1);
1142 * // $users['123'] = 'John Doe'
1144 * $sql = 'SELECT `name` FROM `user`';
1145 * $users = PMA_DBI_fetch_result($sql);
1147 * // $users[] = 'John Doe'
1149 * $sql = 'SELECT `group`, `name` FROM `user`'
1150 * $users = PMA_DBI_fetch_result($sql, array('group', null), 'name');
1152 * // $users['admin'][] = 'John Doe'
1154 * $sql = 'SELECT `group`, `name` FROM `user`'
1155 * $users = PMA_DBI_fetch_result($sql, array('group', 'name'), 'id');
1157 * // $users['admin']['John Doe'] = '123'
1162 * @uses PMA_DBI_try_query()
1163 * @uses PMA_DBI_num_rows()
1164 * @uses PMA_DBI_num_fields()
1165 * @uses PMA_DBI_fetch_row()
1166 * @uses PMA_DBI_fetch_assoc()
1167 * @uses PMA_DBI_free_result()
1168 * @param string|mysql_result $result query or mysql result
1169 * @param string|integer $key field-name or offset
1170 * used as key for array
1171 * @param string|integer $value value-name or offset
1172 * used as value for array
1173 * @param resource $link mysql link
1174 * @param mixed $options
1175 * @return array resultrows or values indexed by $key
1177 function PMA_DBI_fetch_result($result, $key = null, $value = null,
1178 $link = null, $options = 0)
1180 $resultrows = array();
1182 if (is_string($result)) {
1183 $result = PMA_DBI_try_query($result, $link, $options);
1186 // return empty array if result is empty or false
1191 $fetch_function = 'PMA_DBI_fetch_assoc';
1193 // no nested array if only one field is in result
1194 if (null === $key && 1 === PMA_DBI_num_fields($result)) {
1196 $fetch_function = 'PMA_DBI_fetch_row';
1199 // if $key is an integer use non associative mysql fetch function
1201 $fetch_function = 'PMA_DBI_fetch_row';
1204 if (null === $key && null === $value) {
1205 while ($row = $fetch_function($result)) {
1206 $resultrows[] = $row;
1208 } elseif (null === $key) {
1209 while ($row = $fetch_function($result)) {
1210 $resultrows[] = $row[$value];
1212 } elseif (null === $value) {
1213 if (is_array($key)) {
1214 while ($row = $fetch_function($result)) {
1215 $result_target =& $resultrows;
1216 foreach ($key as $key_index) {
1217 if (null === $key_index) {
1218 $result_target =& $result_target[];
1222 if (! isset($result_target[$row[$key_index]])) {
1223 $result_target[$row[$key_index]] = array();
1225 $result_target =& $result_target[$row[$key_index]];
1227 $result_target = $row;
1230 while ($row = $fetch_function($result)) {
1231 $resultrows[$row[$key]] = $row;
1235 if (is_array($key)) {
1236 while ($row = $fetch_function($result)) {
1237 $result_target =& $resultrows;
1238 foreach ($key as $key_index) {
1239 if (null === $key_index) {
1240 $result_target =& $result_target[];
1244 if (! isset($result_target[$row[$key_index]])) {
1245 $result_target[$row[$key_index]] = array();
1247 $result_target =& $result_target[$row[$key_index]];
1249 $result_target = $row[$value];
1252 while ($row = $fetch_function($result)) {
1253 $resultrows[$row[$key]] = $row[$value];
1258 PMA_DBI_free_result($result);
1263 * return default table engine for given database
1265 * @return string default table engine
1267 function PMA_DBI_get_default_engine()
1269 return PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
1273 * Get supported SQL compatibility modes
1275 * @return array supported SQL compatibility modes
1277 function PMA_DBI_getCompatibilities()
1279 $compats = array('NONE');
1280 $compats[] = 'ANSI';
1282 $compats[] = 'MAXDB';
1283 $compats[] = 'MYSQL323';
1284 $compats[] = 'MYSQL40';
1285 $compats[] = 'MSSQL';
1286 $compats[] = 'ORACLE';
1287 // removed; in MySQL 5.0.33, this produces exports that
1288 // can't be read by POSTGRESQL (see our bug #1596328)
1289 //$compats[] = 'POSTGRESQL';
1290 $compats[] = 'TRADITIONAL';
1296 * returns warnings for last query
1298 * @uses $GLOBALS['userlink']
1299 * @uses PMA_DBI_fetch_result()
1300 * @param resource mysql link $link mysql link resource
1301 * @return array warnings
1303 function PMA_DBI_get_warnings($link = null)
1306 if (isset($GLOBALS['userlink'])) {
1307 $link = $GLOBALS['userlink'];
1313 return PMA_DBI_fetch_result('SHOW WARNINGS', null, null, $link);
1317 * returns true (int > 0) if current user is superuser
1320 * @uses $_SESSION['is_superuser'] for caching
1321 * @uses $GLOBALS['userlink']
1322 * @uses $GLOBALS['server']
1323 * @uses PMA_DBI_try_query()
1324 * @uses PMA_DBI_QUERY_STORE
1325 * @return integer $is_superuser
1327 function PMA_isSuperuser()
1329 if (PMA_cacheExists('is_superuser', true)) {
1330 return PMA_cacheGet('is_superuser', true);
1333 // with mysql extension, when connection failed we don't have
1335 if (isset($GLOBALS['userlink'])) {
1336 $r = (bool) PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', $GLOBALS['userlink'], PMA_DBI_QUERY_STORE
);
1337 PMA_cacheSet('is_superuser', $r, true);
1339 PMA_cacheSet('is_superuser', false, true);
1342 return PMA_cacheGet('is_superuser', true);
1346 * returns an array of PROCEDURE or FUNCTION names for a db
1348 * @uses PMA_DBI_free_result()
1349 * @param string $db db name
1350 * @param string $which PROCEDURE | FUNCTION
1351 * @param resource $link mysql link
1353 * @return array the procedure names or function names
1355 function PMA_DBI_get_procedures_or_functions($db, $which, $link = null)
1357 $shows = PMA_DBI_fetch_result('SHOW ' . $which . ' STATUS;', null, null, $link);
1359 foreach ($shows as $one_show) {
1360 if ($one_show['Db'] == $db && $one_show['Type'] == $which) {
1361 $result[] = $one_show['Name'];
1368 * returns the definition of a specific PROCEDURE, FUNCTION or EVENT
1370 * @uses PMA_DBI_fetch_value()
1371 * @param string $db db name
1372 * @param string $which PROCEDURE | FUNCTION | EVENT
1373 * @param string $name the procedure|function|event name
1374 * @param resource $link mysql link
1376 * @return string the definition
1378 function PMA_DBI_get_definition($db, $which, $name, $link = null)
1380 $returned_field = array(
1381 'PROCEDURE' => 'Create Procedure',
1382 'FUNCTION' => 'Create Function',
1383 'EVENT' => 'Create Event'
1385 $query = 'SHOW CREATE ' . $which . ' ' . PMA_backquote($db) . '.' . PMA_backquote($name);
1386 return(PMA_DBI_fetch_value($query, 0, $returned_field[$which]));
1390 * returns details about the TRIGGERs of a specific table
1392 * @uses PMA_DBI_fetch_result()
1393 * @param string $db db name
1394 * @param string $table table name
1395 * @param string $delimiter the delimiter to use (may be empty)
1397 * @return array information about triggers (may be empty)
1399 function PMA_DBI_get_triggers($db, $table, $delimiter = '//')
1403 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
1404 // Note: in http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html
1405 // their example uses WHERE TRIGGER_SCHEMA='dbname' so let's use this
1406 // instead of WHERE EVENT_OBJECT_SCHEMA='dbname'
1407 $triggers = PMA_DBI_fetch_result("SELECT TRIGGER_SCHEMA, TRIGGER_NAME, EVENT_MANIPULATION, ACTION_TIMING, ACTION_STATEMENT, EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA= '" . PMA_sqlAddslashes($db,true) . "' and EVENT_OBJECT_TABLE = '" . PMA_sqlAddslashes($table, true) . "';");
1409 $triggers = PMA_DBI_fetch_result("SHOW TRIGGERS FROM " . PMA_sqlAddslashes($db,true) . " LIKE '" . PMA_sqlAddslashes($table, true) . "';");
1413 foreach ($triggers as $trigger) {
1414 if ($GLOBALS['cfg']['Server']['DisableIS']) {
1415 $trigger['TRIGGER_NAME'] = $trigger['Trigger'];
1416 $trigger['ACTION_TIMING'] = $trigger['Timing'];
1417 $trigger['EVENT_MANIPULATION'] = $trigger['Event'];
1418 $trigger['EVENT_OBJECT_TABLE'] = $trigger['Table'];
1419 $trigger['ACTION_STATEMENT'] = $trigger['Statement'];
1421 $one_result = array();
1422 $one_result['name'] = $trigger['TRIGGER_NAME'];
1423 $one_result['action_timing'] = $trigger['ACTION_TIMING'];
1424 $one_result['event_manipulation'] = $trigger['EVENT_MANIPULATION'];
1426 // do not prepend the schema name; this way, importing the
1427 // definition into another schema will work
1428 $one_result['full_trigger_name'] = PMA_backquote($trigger['TRIGGER_NAME']);
1429 $one_result['drop'] = 'DROP TRIGGER IF EXISTS ' . $one_result['full_trigger_name'];
1430 $one_result['create'] = 'CREATE TRIGGER ' . $one_result['full_trigger_name'] . ' ' . $trigger['ACTION_TIMING']. ' ' . $trigger['EVENT_MANIPULATION'] . ' ON ' . PMA_backquote($trigger['EVENT_OBJECT_TABLE']) . "\n" . ' FOR EACH ROW ' . $trigger['ACTION_STATEMENT'] . "\n" . $delimiter . "\n";
1432 $result[] = $one_result;
1439 * Returns TRUE if $db.$view_name is a view, FALSE if not
1441 * @uses PMA_DBI_fetch_result()
1442 * @param string $db database name
1443 * @param string $view_name view/table name
1445 * @return bool TRUE if $db.$view_name is a view, FALSE if not
1447 function PMA_isView($db, $view_name)
1449 $result = PMA_DBI_fetch_result("SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$db."' and TABLE_NAME = '".$view_name."';");