2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common Option Constants For DBI Functions
8 if (! defined('PHPMYADMIN')) {
15 // PMA_DBI_try_query()
16 define('PMA_DBI_QUERY_STORE', 1); // Force STORE_RESULT method, ignored by classic MySQL.
17 define('PMA_DBI_QUERY_UNBUFFERED', 2); // Do not read whole query
18 // PMA_DBI_get_variable()
19 define('PMA_DBI_GETVAR_SESSION', 1);
20 define('PMA_DBI_GETVAR_GLOBAL', 2);
23 * Checks one of the mysql extensions
25 * @param string $extension mysql extension to check
27 function PMA_DBI_checkMysqlExtension($extension = 'mysql') {
28 if (! function_exists($extension . '_connect')) {
36 * check for requested extension
38 if (! PMA_DBI_checkMysqlExtension($GLOBALS['cfg']['Server']['extension'])) {
40 // if it fails try alternative extension ...
41 // and display an error ...
44 * @todo add different messages for alternative extension
45 * and complete fail (no alternative extension too)
47 PMA_warnMissingExtension($GLOBALS['cfg']['Server']['extension'], false, PMA_showDocu('faqmysql'));
49 if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') {
50 $alternativ_extension = 'mysqli';
52 $alternativ_extension = 'mysql';
55 if (! PMA_DBI_checkMysqlExtension($alternativ_extension)) {
56 // if alternative fails too ...
57 PMA_warnMissingExtension($GLOBALS['cfg']['Server']['extension'], true, PMA_showDocu('faqmysql'));
60 $GLOBALS['cfg']['Server']['extension'] = $alternativ_extension;
61 unset($alternativ_extension);
65 * Including The DBI Plugin
67 require_once './libraries/dbi/' . $GLOBALS['cfg']['Server']['extension'] . '.dbi.lib.php';
72 function PMA_DBI_query($query, $link = null, $options = 0, $cache_affected_rows = true) {
73 $res = PMA_DBI_try_query($query, $link, $options, $cache_affected_rows)
74 or PMA_mysqlDie(PMA_DBI_getError($link), $query);
79 * converts charset of a mysql message, usually coming from mysql_error(),
80 * into PMA charset, usally UTF-8
81 * uses language to charset mapping from mysql/share/errmsg.txt
82 * and charset names to ISO charset from information_schema.CHARACTER_SETS
84 * @uses $GLOBALS['cfg']['IconvExtraParams']
85 * @uses $GLOBALS['charset'] as target charset
86 * @uses PMA_DBI_fetch_value() to get server_language
87 * @uses preg_match() to filter server_language
89 * @uses function_exists() to check for a convert function
90 * @uses iconv() to convert message
91 * @uses libiconv() to convert message
92 * @uses recode_string() to convert message
93 * @uses mb_convert_encoding() to convert message
94 * @param string $message
95 * @return string $message
97 function PMA_DBI_convert_message($message) {
100 'japanese' => 'EUC-JP', //'ujis',
101 'japanese-sjis' => 'Shift-JIS', //'sjis',
102 'korean' => 'EUC-KR', //'euckr',
103 'russian' => 'KOI8-R', //'koi8r',
104 'ukrainian' => 'KOI8-U', //'koi8u',
105 'greek' => 'ISO-8859-7', //'greek',
106 'serbian' => 'CP1250', //'cp1250',
107 'estonian' => 'ISO-8859-13', //'latin7',
108 'slovak' => 'ISO-8859-2', //'latin2',
109 'czech' => 'ISO-8859-2', //'latin2',
110 'hungarian' => 'ISO-8859-2', //'latin2',
111 'polish' => 'ISO-8859-2', //'latin2',
112 'romanian' => 'ISO-8859-2', //'latin2',
113 'spanish' => 'CP1252', //'latin1',
114 'swedish' => 'CP1252', //'latin1',
115 'italian' => 'CP1252', //'latin1',
116 'norwegian-ny' => 'CP1252', //'latin1',
117 'norwegian' => 'CP1252', //'latin1',
118 'portuguese' => 'CP1252', //'latin1',
119 'danish' => 'CP1252', //'latin1',
120 'dutch' => 'CP1252', //'latin1',
121 'english' => 'CP1252', //'latin1',
122 'french' => 'CP1252', //'latin1',
123 'german' => 'CP1252', //'latin1',
126 if ($server_language = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'language\';', 0, 1)) {
128 if (preg_match('&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', $server_language, $found)) {
129 $server_language = $found[1];
133 if (! empty($server_language) && isset($encodings[$server_language])) {
134 if (function_exists('iconv')) {
135 if ((@stristr
(PHP_OS
, 'AIX')) && (@strcasecmp
(ICONV_IMPL
, 'unknown') == 0) && (@strcasecmp
(ICONV_VERSION
, 'unknown') == 0)) {
136 require_once './libraries/iconv_wrapper.lib.php';
137 $message = PMA_aix_iconv_wrapper($encodings[$server_language],
138 $GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
140 $message = iconv($encodings[$server_language],
141 $GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
143 } elseif (function_exists('recode_string')) {
144 $message = recode_string($encodings[$server_language] . '..' . $GLOBALS['charset'],
146 } elseif (function_exists('libiconv')) {
147 $message = libiconv($encodings[$server_language], $GLOBALS['charset'], $message);
148 } elseif (function_exists('mb_convert_encoding')) {
149 // do not try unsupported charsets
150 if (! in_array($server_language, array('ukrainian', 'greek', 'serbian'))) {
151 $message = mb_convert_encoding($message, $GLOBALS['charset'],
152 $encodings[$server_language]);
157 * @todo lang not found, try all, what TODO ?
165 * returns array with table names for given db
167 * @param string $database name of database
168 * @param mixed $link mysql link resource|object
169 * @return array tables names
171 function PMA_DBI_get_tables($database, $link = null)
173 return PMA_DBI_fetch_result('SHOW TABLES FROM ' . PMA_backquote($database) . ';',
174 null, 0, $link, PMA_DBI_QUERY_STORE
);
178 * usort comparison callback
180 * @param string $a first argument to sort
181 * @param string $b second argument to sort
183 * @return integer a value representing whether $a should be before $b in the
184 * sorted array or not
186 * @global string the column the array shall be sorted by
187 * @global string the sorting order ('ASC' or 'DESC')
191 function PMA_usort_comparison_callback($a, $b)
193 if ($GLOBALS['cfg']['NaturalOrder']) {
194 $sorter = 'strnatcasecmp';
196 $sorter = 'strcasecmp';
198 /* No sorting when key is not present */
199 if (! isset($a[$GLOBALS['callback_sort_by']]) ||
! isset($b[$GLOBALS['callback_sort_by']])) {
203 // return -1 * strnatcasecmp($a["SCHEMA_TABLES"], $b["SCHEMA_TABLES"])
204 return ($GLOBALS['callback_sort_order'] == 'ASC' ?
1 : -1) * $sorter($a[$GLOBALS['callback_sort_by']], $b[$GLOBALS['callback_sort_by']]);
205 } // end of the 'PMA_usort_comparison_callback()' function
208 * returns array of all tables in given db or dbs
209 * this function expects unquoted names:
211 * WRONG: `my_database`
212 * WRONG: my\_database
213 * if $tbl_is_group is true, $table is used as filter for table names
214 * if $tbl_is_group is 'comment, $table is used as filter for table comments
217 * PMA_DBI_get_tables_full('my_database');
218 * PMA_DBI_get_tables_full('my_database', 'my_table'));
219 * PMA_DBI_get_tables_full('my_database', 'my_tables_', true));
220 * PMA_DBI_get_tables_full('my_database', 'my_tables_', 'comment'));
223 * @todo move into PMA_Table
224 * @uses PMA_DBI_fetch_result()
225 * @uses PMA_escape_mysql_wildcards()
226 * @uses PMA_backquote()
231 * @param string $databases database
232 * @param string $table table
233 * @param boolean|string $tbl_is_group $table is a table group
234 * @param resource $link mysql link
235 * @param integer $limit_offset zero-based offset for the count
236 * @param boolean|integer $limit_count number of tables to return
237 * @param string $sort_by table attribute to sort by
238 * @param string $sort_order direction to sort (ASC or DESC)
239 * @return array list of tables in given db(s)
241 function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = false, $link = null,
242 $limit_offset = 0, $limit_count = false, $sort_by = 'Name', $sort_order = 'ASC')
244 if (true === $limit_count) {
245 $limit_count = $GLOBALS['cfg']['MaxTableList'];
247 // prepare and check parameters
248 if (! is_array($database)) {
249 $databases = array($database);
251 $databases = $database;
256 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
257 // get table information from information_schema
259 if (true === $tbl_is_group) {
260 $sql_where_table = 'AND `TABLE_NAME` LIKE \''
261 . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
262 } elseif ('comment' === $tbl_is_group) {
263 $sql_where_table = 'AND `TABLE_COMMENT` LIKE \''
264 . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
266 $sql_where_table = 'AND `TABLE_NAME` = \'' . addslashes($table) . '\'';
269 $sql_where_table = '';
273 // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME`
275 // on non-Windows servers,
276 // added BINARY in the WHERE clause to force a case sensitive
277 // comparison (if we are looking for the db Aa we don't want
278 // to find the db aa)
279 $this_databases = array_map('PMA_sqlAddslashes', $databases);
283 `TABLE_SCHEMA` AS `Db`,
284 `TABLE_NAME` AS `Name`,
285 `TABLE_TYPE` AS `TABLE_TYPE`,
286 `ENGINE` AS `Engine`,
288 `VERSION` AS `Version`,
289 `ROW_FORMAT` AS `Row_format`,
290 `TABLE_ROWS` AS `Rows`,
291 `AVG_ROW_LENGTH` AS `Avg_row_length`,
292 `DATA_LENGTH` AS `Data_length`,
293 `MAX_DATA_LENGTH` AS `Max_data_length`,
294 `INDEX_LENGTH` AS `Index_length`,
295 `DATA_FREE` AS `Data_free`,
296 `AUTO_INCREMENT` AS `Auto_increment`,
297 `CREATE_TIME` AS `Create_time`,
298 `UPDATE_TIME` AS `Update_time`,
299 `CHECK_TIME` AS `Check_time`,
300 `TABLE_COLLATION` AS `Collation`,
301 `CHECKSUM` AS `Checksum`,
302 `CREATE_OPTIONS` AS `Create_options`,
303 `TABLE_COMMENT` AS `Comment`
304 FROM `information_schema`.`TABLES`
305 WHERE ' . (PMA_IS_WINDOWS ?
'' : 'BINARY') . ' `TABLE_SCHEMA` IN (\'' . implode("', '", $this_databases) . '\')
306 ' . $sql_where_table;
309 $sql .= " ORDER BY $sort_by $sort_order";
312 $sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset;
315 $tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA', 'TABLE_NAME'),
317 unset($sql_where_table, $sql);
318 if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) {
319 // here, the array's first key is by schema name
320 foreach($tables as $one_database_name => $one_database_tables) {
321 uksort($one_database_tables, 'strnatcasecmp');
323 if ($sort_order == 'DESC') {
324 $one_database_tables = array_reverse($one_database_tables);
326 $tables[$one_database_name] = $one_database_tables;
329 } // end (get information from table schema)
331 // If permissions are wrong on even one database directory,
332 // information_schema does not return any table info for any database
333 // this is why we fall back to SHOW TABLE STATUS even for MySQL >= 50002
334 if (empty($tables)) {
335 foreach ($databases as $each_database) {
336 if ($table ||
(true === $tbl_is_group)) {
337 $sql = 'SHOW TABLE STATUS FROM '
338 . PMA_backquote($each_database)
339 .' LIKE \'' . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
341 $sql = 'SHOW TABLE STATUS FROM '
342 . PMA_backquote($each_database);
345 $each_tables = PMA_DBI_fetch_result($sql, 'Name', null, $link);
347 // Sort naturally if the config allows it and we're sorting
349 if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) {
350 uksort($each_tables, 'strnatcasecmp');
352 if ($sort_order == 'DESC') {
353 $each_tables = array_reverse($each_tables);
356 // Prepare to sort by creating array of the selected sort
357 // value to pass to array_multisort
359 // Size = Data_length + Index_length
360 if ($sort_by == 'Data_length') {
361 foreach ($each_tables as $table_name => $table_data) {
362 $
{$sort_by}[$table_name] = strtolower($table_data['Data_length'] +
$table_data['Index_length']);
365 foreach ($each_tables as $table_name => $table_data) {
366 $
{$sort_by}[$table_name] = strtolower($table_data[$sort_by]);
370 if ($sort_order == 'DESC') {
371 array_multisort($
$sort_by, SORT_DESC
, $each_tables);
373 array_multisort($
$sort_by, SORT_ASC
, $each_tables);
376 // cleanup the temporary sort array
381 $each_tables = array_slice($each_tables, $limit_offset, $limit_count);
384 foreach ($each_tables as $table_name => $each_table) {
385 if ('comment' === $tbl_is_group
386 && 0 === strpos($each_table['Comment'], $table))
388 // remove table from list
389 unset($each_tables[$table_name]);
393 if (! isset($each_tables[$table_name]['Type'])
394 && isset($each_tables[$table_name]['Engine'])) {
395 // pma BC, same parts of PMA still uses 'Type'
396 $each_tables[$table_name]['Type']
397 =& $each_tables[$table_name]['Engine'];
398 } elseif (! isset($each_tables[$table_name]['Engine'])
399 && isset($each_tables[$table_name]['Type'])) {
400 // old MySQL reports Type, newer MySQL reports Engine
401 $each_tables[$table_name]['Engine']
402 =& $each_tables[$table_name]['Type'];
405 // MySQL forward compatibility
406 // so pma could use this array as if every server is of version >5.0
407 $each_tables[$table_name]['TABLE_SCHEMA'] = $each_database;
408 $each_tables[$table_name]['TABLE_NAME'] =& $each_tables[$table_name]['Name'];
409 $each_tables[$table_name]['ENGINE'] =& $each_tables[$table_name]['Engine'];
410 $each_tables[$table_name]['VERSION'] =& $each_tables[$table_name]['Version'];
411 $each_tables[$table_name]['ROW_FORMAT'] =& $each_tables[$table_name]['Row_format'];
412 $each_tables[$table_name]['TABLE_ROWS'] =& $each_tables[$table_name]['Rows'];
413 $each_tables[$table_name]['AVG_ROW_LENGTH'] =& $each_tables[$table_name]['Avg_row_length'];
414 $each_tables[$table_name]['DATA_LENGTH'] =& $each_tables[$table_name]['Data_length'];
415 $each_tables[$table_name]['MAX_DATA_LENGTH'] =& $each_tables[$table_name]['Max_data_length'];
416 $each_tables[$table_name]['INDEX_LENGTH'] =& $each_tables[$table_name]['Index_length'];
417 $each_tables[$table_name]['DATA_FREE'] =& $each_tables[$table_name]['Data_free'];
418 $each_tables[$table_name]['AUTO_INCREMENT'] =& $each_tables[$table_name]['Auto_increment'];
419 $each_tables[$table_name]['CREATE_TIME'] =& $each_tables[$table_name]['Create_time'];
420 $each_tables[$table_name]['UPDATE_TIME'] =& $each_tables[$table_name]['Update_time'];
421 $each_tables[$table_name]['CHECK_TIME'] =& $each_tables[$table_name]['Check_time'];
422 $each_tables[$table_name]['TABLE_COLLATION'] =& $each_tables[$table_name]['Collation'];
423 $each_tables[$table_name]['CHECKSUM'] =& $each_tables[$table_name]['Checksum'];
424 $each_tables[$table_name]['CREATE_OPTIONS'] =& $each_tables[$table_name]['Create_options'];
425 $each_tables[$table_name]['TABLE_COMMENT'] =& $each_tables[$table_name]['Comment'];
427 if (strtoupper($each_tables[$table_name]['Comment']) === 'VIEW'
428 && $each_tables[$table_name]['Engine'] == NULL) {
429 $each_tables[$table_name]['TABLE_TYPE'] = 'VIEW';
432 * @todo difference between 'TEMPORARY' and 'BASE TABLE' but how to detect?
434 $each_tables[$table_name]['TABLE_TYPE'] = 'BASE TABLE';
438 $tables[$each_database] = $each_tables;
443 // so PMA_Table does not require to issue SHOW TABLE STATUS again
444 // Note: I don't see why we would need array_merge_recursive() here,
445 // as it creates double entries for the same table (for example a double
446 // entry for Comment when changing the storage engine in Operations)
447 // Note 2: Instead of array_merge(), simply use the + operator because
448 // array_merge() renumbers numeric keys starting with 0, therefore
449 // we would lose a db name thats consists only of numbers
450 foreach($tables as $one_database => $its_tables) {
451 if (isset(PMA_Table
::$cache[$one_database])) {
452 PMA_Table
::$cache[$one_database] = PMA_Table
::$cache[$one_database] +
$tables[$one_database];
454 PMA_Table
::$cache[$one_database] = $tables[$one_database];
457 unset($one_database, $its_tables);
459 if (! is_array($database)) {
460 if (isset($tables[$database])) {
461 return $tables[$database];
462 } elseif (isset($tables[strtolower($database)])) {
463 // on windows with lower_case_table_names = 1
465 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
466 // but information_schema.TABLES gives `test`
468 // http://sf.net/support/tracker.php?aid=1436171
469 return $tables[strtolower($database)];
479 * returns array with databases containing extended infos about them
481 * @todo move into PMA_List_Database?
482 * @param string $database database
483 * @param boolean $force_stats retrieve stats also for MySQL < 5
484 * @param resource $link mysql link
485 * @param string $sort_by column to order by
486 * @param string $sort_order ASC or DESC
487 * @param integer $limit_offset starting offset for LIMIT
488 * @param bool|int $limit_count row count for LIMIT or true for $GLOBALS['cfg']['MaxDbList']
489 * @return array $databases
491 function PMA_DBI_get_databases_full($database = null, $force_stats = false,
492 $link = null, $sort_by = 'SCHEMA_NAME', $sort_order = 'ASC',
493 $limit_offset = 0, $limit_count = false)
495 $sort_order = strtoupper($sort_order);
497 if (true === $limit_count) {
498 $limit_count = $GLOBALS['cfg']['MaxDbList'];
501 // initialize to avoid errors when there are no databases
502 $databases = array();
504 $apply_limit_and_order_manual = true;
506 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
508 * if $GLOBALS['cfg']['NaturalOrder'] is enabled, we cannot use LIMIT
509 * cause MySQL does not support natural ordering, we have to do it afterward
512 if (!$GLOBALS['cfg']['NaturalOrder']) {
514 $limit = ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset;
517 $apply_limit_and_order_manual = false;
520 // get table information from information_schema
522 $sql_where_schema = 'WHERE `SCHEMA_NAME` LIKE \''
523 . addslashes($database) . '\'';
525 $sql_where_schema = '';
529 // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME`
531 SELECT `information_schema`.`SCHEMATA`.*';
534 COUNT(`information_schema`.`TABLES`.`TABLE_SCHEMA`)
536 SUM(`information_schema`.`TABLES`.`TABLE_ROWS`)
537 AS `SCHEMA_TABLE_ROWS`,
538 SUM(`information_schema`.`TABLES`.`DATA_LENGTH`)
539 AS `SCHEMA_DATA_LENGTH`,
540 SUM(`information_schema`.`TABLES`.`MAX_DATA_LENGTH`)
541 AS `SCHEMA_MAX_DATA_LENGTH`,
542 SUM(`information_schema`.`TABLES`.`INDEX_LENGTH`)
543 AS `SCHEMA_INDEX_LENGTH`,
544 SUM(`information_schema`.`TABLES`.`DATA_LENGTH`
545 + `information_schema`.`TABLES`.`INDEX_LENGTH`)
547 SUM(`information_schema`.`TABLES`.`DATA_FREE`)
548 AS `SCHEMA_DATA_FREE`';
551 FROM `information_schema`.`SCHEMATA`';
554 LEFT JOIN `information_schema`.`TABLES`
555 ON BINARY `information_schema`.`TABLES`.`TABLE_SCHEMA`
556 = BINARY `information_schema`.`SCHEMATA`.`SCHEMA_NAME`';
559 ' . $sql_where_schema . '
560 GROUP BY BINARY `information_schema`.`SCHEMATA`.`SCHEMA_NAME`
561 ORDER BY BINARY ' . PMA_backquote($sort_by) . ' ' . $sort_order
563 $databases = PMA_DBI_fetch_result($sql, 'SCHEMA_NAME', null, $link);
565 $mysql_error = PMA_DBI_getError($link);
566 if (! count($databases) && $GLOBALS['errno']) {
567 PMA_mysqlDie($mysql_error, $sql);
570 // display only databases also in official database list
571 // f.e. to apply hide_db and only_db
572 $drops = array_diff(array_keys($databases), (array) $GLOBALS['pma']->databases
);
574 foreach ($drops as $drop) {
575 unset($databases[$drop]);
579 unset($sql_where_schema, $sql, $drops);
581 foreach ($GLOBALS['pma']->databases
as $database_name) {
582 // MySQL forward compatibility
583 // so pma could use this array as if every server is of version >5.0
584 $databases[$database_name]['SCHEMA_NAME'] = $database_name;
587 require_once './libraries/mysql_charsets.lib.php';
589 $databases[$database_name]['DEFAULT_COLLATION_NAME']
590 = PMA_getDbCollation($database_name);
592 // get additional info about tables
593 $databases[$database_name]['SCHEMA_TABLES'] = 0;
594 $databases[$database_name]['SCHEMA_TABLE_ROWS'] = 0;
595 $databases[$database_name]['SCHEMA_DATA_LENGTH'] = 0;
596 $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] = 0;
597 $databases[$database_name]['SCHEMA_INDEX_LENGTH'] = 0;
598 $databases[$database_name]['SCHEMA_LENGTH'] = 0;
599 $databases[$database_name]['SCHEMA_DATA_FREE'] = 0;
601 $res = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($database_name) . ';');
602 while ($row = PMA_DBI_fetch_assoc($res)) {
603 $databases[$database_name]['SCHEMA_TABLES']++
;
604 $databases[$database_name]['SCHEMA_TABLE_ROWS']
606 $databases[$database_name]['SCHEMA_DATA_LENGTH']
607 +
= $row['Data_length'];
608 $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH']
609 +
= $row['Max_data_length'];
610 $databases[$database_name]['SCHEMA_INDEX_LENGTH']
611 +
= $row['Index_length'];
613 // for InnoDB, this does not contain the number of
614 // overhead bytes but the total free space
615 if ('InnoDB' != $row['Engine']) {
616 $databases[$database_name]['SCHEMA_DATA_FREE']
617 +
= $row['Data_free'];
619 $databases[$database_name]['SCHEMA_LENGTH']
620 +
= $row['Data_length'] +
$row['Index_length'];
622 PMA_DBI_free_result($res);
630 * apply limit and order manually now
631 * (caused by older MySQL < 5 or $GLOBALS['cfg']['NaturalOrder'])
633 if ($apply_limit_and_order_manual) {
634 $GLOBALS['callback_sort_order'] = $sort_order;
635 $GLOBALS['callback_sort_by'] = $sort_by;
636 usort($databases, 'PMA_usort_comparison_callback');
637 unset($GLOBALS['callback_sort_order'], $GLOBALS['callback_sort_by']);
643 $databases = array_slice($databases, $limit_offset, $limit_count);
651 * returns detailed array with all columns for given table in database,
652 * or all tables/databases
654 * @param string $database name of database
655 * @param string $table name of table to retrieve columns from
656 * @param string $column name of specific column
657 * @param mixed $link mysql link resource
659 function PMA_DBI_get_columns_full($database = null, $table = null,
660 $column = null, $link = null)
664 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
665 $sql_wheres = array();
666 $array_keys = array();
668 // get columns information from information_schema
669 if (null !== $database) {
670 $sql_wheres[] = '`TABLE_SCHEMA` = \'' . addslashes($database) . '\' ';
672 $array_keys[] = 'TABLE_SCHEMA';
674 if (null !== $table) {
675 $sql_wheres[] = '`TABLE_NAME` = \'' . addslashes($table) . '\' ';
677 $array_keys[] = 'TABLE_NAME';
679 if (null !== $column) {
680 $sql_wheres[] = '`COLUMN_NAME` = \'' . addslashes($column) . '\' ';
682 $array_keys[] = 'COLUMN_NAME';
686 // `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]`
689 `COLUMN_NAME` AS `Field`,
690 `COLUMN_TYPE` AS `Type`,
691 `COLLATION_NAME` AS `Collation`,
692 `IS_NULLABLE` AS `Null`,
693 `COLUMN_KEY` AS `Key`,
694 `COLUMN_DEFAULT` AS `Default`,
696 `PRIVILEGES` AS `Privileges`,
697 `COLUMN_COMMENT` AS `Comment`
698 FROM `information_schema`.`COLUMNS`';
699 if (count($sql_wheres)) {
700 $sql .= "\n" . ' WHERE ' . implode(' AND ', $sql_wheres);
703 $columns = PMA_DBI_fetch_result($sql, $array_keys, null, $link);
704 unset($sql_wheres, $sql);
706 if (null === $database) {
707 foreach ($GLOBALS['pma']->databases
as $database) {
708 $columns[$database] = PMA_DBI_get_columns_full($database, null,
712 } elseif (null === $table) {
713 $tables = PMA_DBI_get_tables($database);
714 foreach ($tables as $table) {
715 $columns[$table] = PMA_DBI_get_columns_full(
716 $database, $table, null, $link);
721 $sql = 'SHOW FULL COLUMNS FROM '
722 . PMA_backquote($database) . '.' . PMA_backquote($table);
723 if (null !== $column) {
724 $sql .= " LIKE '" . $column . "'";
727 $columns = PMA_DBI_fetch_result($sql, 'Field', null, $link);
729 $ordinal_position = 1;
730 foreach ($columns as $column_name => $each_column) {
732 // MySQL forward compatibility
733 // so pma could use this array as if every server is of version >5.0
734 $columns[$column_name]['COLUMN_NAME'] =& $columns[$column_name]['Field'];
735 $columns[$column_name]['COLUMN_TYPE'] =& $columns[$column_name]['Type'];
736 $columns[$column_name]['COLLATION_NAME'] =& $columns[$column_name]['Collation'];
737 $columns[$column_name]['IS_NULLABLE'] =& $columns[$column_name]['Null'];
738 $columns[$column_name]['COLUMN_KEY'] =& $columns[$column_name]['Key'];
739 $columns[$column_name]['COLUMN_DEFAULT'] =& $columns[$column_name]['Default'];
740 $columns[$column_name]['EXTRA'] =& $columns[$column_name]['Extra'];
741 $columns[$column_name]['PRIVILEGES'] =& $columns[$column_name]['Privileges'];
742 $columns[$column_name]['COLUMN_COMMENT'] =& $columns[$column_name]['Comment'];
744 $columns[$column_name]['TABLE_CATALOG'] = null;
745 $columns[$column_name]['TABLE_SCHEMA'] = $database;
746 $columns[$column_name]['TABLE_NAME'] = $table;
747 $columns[$column_name]['ORDINAL_POSITION'] = $ordinal_position;
748 $columns[$column_name]['DATA_TYPE'] =
749 substr($columns[$column_name]['COLUMN_TYPE'], 0,
750 strpos($columns[$column_name]['COLUMN_TYPE'], '('));
752 * @todo guess CHARACTER_MAXIMUM_LENGTH from COLUMN_TYPE
754 $columns[$column_name]['CHARACTER_MAXIMUM_LENGTH'] = null;
756 * @todo guess CHARACTER_OCTET_LENGTH from CHARACTER_MAXIMUM_LENGTH
758 $columns[$column_name]['CHARACTER_OCTET_LENGTH'] = null;
759 $columns[$column_name]['NUMERIC_PRECISION'] = null;
760 $columns[$column_name]['NUMERIC_SCALE'] = null;
761 $columns[$column_name]['CHARACTER_SET_NAME'] =
762 substr($columns[$column_name]['COLLATION_NAME'], 0,
763 strpos($columns[$column_name]['COLLATION_NAME'], '_'));
768 if (null !== $column) {
770 $columns = current($columns);
778 * array PMA_DBI_get_columns(string $database, string $table, bool $full = false, mysql db link $link = null)
780 * @param string $database name of database
781 * @param string $table name of table to retrieve columns from
782 * @param boolean $full whether to return full info or only column names
783 * @param mixed $link mysql link resource
784 * @return array column names
786 function PMA_DBI_get_columns($database, $table, $full = false, $link = null)
788 $fields = PMA_DBI_fetch_result(
789 'SHOW ' . ($full ?
'FULL' : '') . ' COLUMNS
790 FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table),
791 'Field', ($full ?
null : 'Field'), $link);
792 if (! is_array($fields) ||
count($fields) < 1) {
799 * array PMA_DBI_get_column_values (string $database, string $table, string $column , mysql db link $link = null)
801 * @param string $database name of database
802 * @param string $table name of table to retrieve columns from
803 * @param string $column name of the column to retrieve data from
804 * @param mixed $link mysql link resource
805 * @return array $field_values
808 function PMA_DBI_get_column_values($database, $table, $column, $link = null)
811 for($i=0; $i< sizeof($column); $i++
)
813 $query.= PMA_backquote($column[$i]);
814 if($i < (sizeof($column)-1))
819 $query.= ' FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table);
820 $field_values = PMA_DBI_fetch_result($query, null, null, $link);
822 if (! is_array($field_values) ||
count($field_values) < 1) {
825 return $field_values;
828 * array PMA_DBI_get_table_data (string $database, string $table, 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 mixed $link mysql link resource
833 * @return array $result
836 function PMA_DBI_get_table_data($database, $table, $link = null)
839 $result = PMA_DBI_fetch_result(
840 'SELECT * FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table),
843 if (! is_array($result) ||
count($result) < 1) {
850 * array PMA_DBI_get_table_indexes($database, $table, $link = null)
852 * @param string $database name of database
853 * @param string $table name of the table whose indexes are to be retreived
854 * @param mixed $link mysql link resource
855 * @return array $indexes
858 function PMA_DBI_get_table_indexes($database, $table, $link = null)
861 $indexes = PMA_DBI_fetch_result(
862 'SHOW INDEXES FROM ' .PMA_backquote($database) . '.' . PMA_backquote($table),
865 if (! is_array($indexes) ||
count($indexes) < 1) {
872 * returns value of given mysql server variable
874 * @param string $var mysql server variable name
875 * @param int $type PMA_DBI_GETVAR_SESSION|PMA_DBI_GETVAR_GLOBAL
876 * @param mixed $link mysql link resource|object
877 * @return mixed value for mysql server variable
881 function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION
, $link = null)
883 if ($link === null) {
884 if (isset($GLOBALS['userlink'])) {
885 $link = $GLOBALS['userlink'];
892 case PMA_DBI_GETVAR_SESSION
:
893 $modifier = ' SESSION';
895 case PMA_DBI_GETVAR_GLOBAL
:
896 $modifier = ' GLOBAL';
901 return PMA_DBI_fetch_value(
902 'SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 0, 1, $link);
906 * Function called just after a connection to the MySQL database server has been established
907 * It sets the connection collation, and determins the version of MySQL which is running.
909 * @uses ./libraries/charset_conversion.lib.php
910 * @uses PMA_DBI_QUERY_STORE
911 * @uses PMA_MYSQL_INT_VERSION to set it
912 * @uses PMA_MYSQL_STR_VERSION to set it
913 * @uses $_SESSION['PMA_MYSQL_INT_VERSION'] for caching
914 * @uses $_SESSION['PMA_MYSQL_STR_VERSION'] for caching
915 * @uses PMA_DBI_GETVAR_SESSION
916 * @uses PMA_DBI_fetch_value()
917 * @uses PMA_DBI_query()
918 * @uses PMA_DBI_get_variable()
919 * @uses $GLOBALS['collation_connection']
920 * @uses $GLOBALS['available_languages']
921 * @uses $GLOBALS['mysql_charset_map']
922 * @uses $GLOBALS['charset']
923 * @uses $GLOBALS['lang']
924 * @uses $GLOBALS['cfg']['Lang']
933 * @param mixed $link mysql link resource|object
934 * @param boolean $is_controluser
936 function PMA_DBI_postConnect($link, $is_controluser = false)
938 if (! defined('PMA_MYSQL_INT_VERSION')) {
939 if (PMA_cacheExists('PMA_MYSQL_INT_VERSION', true)) {
940 define('PMA_MYSQL_INT_VERSION', PMA_cacheGet('PMA_MYSQL_INT_VERSION', true));
941 define('PMA_MYSQL_MAJOR_VERSION', PMA_cacheGet('PMA_MYSQL_MAJOR_VERSION', true));
942 define('PMA_MYSQL_STR_VERSION', PMA_cacheGet('PMA_MYSQL_STR_VERSION', true));
944 $mysql_version = PMA_DBI_fetch_value(
945 'SELECT VERSION()', 0, 0, $link, PMA_DBI_QUERY_STORE
);
946 if ($mysql_version) {
947 $match = explode('.', $mysql_version);
948 define('PMA_MYSQL_MAJOR_VERSION', (int)$match[0]);
949 define('PMA_MYSQL_INT_VERSION',
950 (int) sprintf('%d%02d%02d', $match[0], $match[1],
952 define('PMA_MYSQL_STR_VERSION', $mysql_version);
953 unset($mysql_version, $match);
955 define('PMA_MYSQL_INT_VERSION', 50015);
956 define('PMA_MYSQL_MAJOR_VERSION', 5);
957 define('PMA_MYSQL_STR_VERSION', '5.00.15');
959 PMA_cacheSet('PMA_MYSQL_INT_VERSION', PMA_MYSQL_INT_VERSION
, true);
960 PMA_cacheSet('PMA_MYSQL_MAJOR_VERSION', PMA_MYSQL_MAJOR_VERSION
, true);
961 PMA_cacheSet('PMA_MYSQL_STR_VERSION', PMA_MYSQL_STR_VERSION
, true);
963 // detect Drizzle by version number (year.month.day.?patch-version)
964 define('PMA_DRIZZLE', PMA_MYSQL_MAJOR_VERSION
>= 2009);
967 // Skip charsets for Drizzle
969 if (! empty($GLOBALS['collation_connection'])) {
970 PMA_DBI_query("SET CHARACTER SET 'utf8';", $link, PMA_DBI_QUERY_STORE
);
971 PMA_DBI_query("SET collation_connection = '" . PMA_sqlAddslashes($GLOBALS['collation_connection']) . "';", $link, PMA_DBI_QUERY_STORE
);
973 PMA_DBI_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci';", $link, PMA_DBI_QUERY_STORE
);
979 * returns a single value from the given result or query,
980 * if the query or the result has more than one row or field
981 * the first field of the first row is returned
984 * $sql = 'SELECT `name` FROM `user` WHERE `id` = 123';
985 * $user_name = PMA_DBI_fetch_value($sql);
987 * // $user_name = 'John Doe'
992 * @uses PMA_DBI_try_query()
993 * @uses PMA_DBI_num_rows()
994 * @uses PMA_DBI_fetch_row()
995 * @uses PMA_DBI_fetch_assoc()
996 * @uses PMA_DBI_free_result()
997 * @param string|mysql_result $result query or mysql result
998 * @param integer $row_number row to fetch the value from,
999 * starting at 0, with 0 beeing default
1000 * @param integer|string $field field to fetch the value from,
1001 * starting at 0, with 0 beeing default
1002 * @param resource $link mysql link
1003 * @param mixed $options
1004 * @return mixed value of first field in first row from result
1005 * or false if not found
1007 function PMA_DBI_fetch_value($result, $row_number = 0, $field = 0, $link = null, $options = 0) {
1010 if (is_string($result)) {
1011 $result = PMA_DBI_try_query($result, $link, $options | PMA_DBI_QUERY_STORE
);
1014 // return false if result is empty or false
1015 // or requested row is larger than rows in result
1016 if (PMA_DBI_num_rows($result) < ($row_number +
1)) {
1020 // if $field is an integer use non associative mysql fetch function
1021 if (is_int($field)) {
1022 $fetch_function = 'PMA_DBI_fetch_row';
1024 $fetch_function = 'PMA_DBI_fetch_assoc';
1027 // get requested row
1028 for ($i = 0; $i <= $row_number; $i++
) {
1029 $row = $fetch_function($result);
1031 PMA_DBI_free_result($result);
1033 // return requested field
1034 if (isset($row[$field])) {
1035 $value = $row[$field];
1043 * returns only the first row from the result
1046 * $sql = 'SELECT * FROM `user` WHERE `id` = 123';
1047 * $user = PMA_DBI_fetch_single_row($sql);
1049 * // $user = array('id' => 123, 'name' => 'John Doe')
1053 * @uses PMA_DBI_try_query()
1054 * @uses PMA_DBI_num_rows()
1055 * @uses PMA_DBI_fetch_row()
1056 * @uses PMA_DBI_fetch_assoc()
1057 * @uses PMA_DBI_fetch_array()
1058 * @uses PMA_DBI_free_result()
1059 * @param string|mysql_result $result query or mysql result
1060 * @param string $type NUM|ASSOC|BOTH
1061 * returned array should either numeric
1062 * associativ or booth
1063 * @param resource $link mysql link
1064 * @param mixed $options
1065 * @return array|boolean first row from result
1066 * or false if result is empty
1068 function PMA_DBI_fetch_single_row($result, $type = 'ASSOC', $link = null, $options = 0) {
1069 if (is_string($result)) {
1070 $result = PMA_DBI_try_query($result, $link, $options | PMA_DBI_QUERY_STORE
);
1073 // return null if result is empty or false
1074 if (! PMA_DBI_num_rows($result)) {
1080 $fetch_function = 'PMA_DBI_fetch_row';
1083 $fetch_function = 'PMA_DBI_fetch_assoc';
1087 $fetch_function = 'PMA_DBI_fetch_array';
1091 $row = $fetch_function($result);
1092 PMA_DBI_free_result($result);
1097 * returns all rows in the resultset in one array
1100 * $sql = 'SELECT * FROM `user`';
1101 * $users = PMA_DBI_fetch_result($sql);
1103 * // $users[] = array('id' => 123, 'name' => 'John Doe')
1105 * $sql = 'SELECT `id`, `name` FROM `user`';
1106 * $users = PMA_DBI_fetch_result($sql, 'id');
1108 * // $users['123'] = array('id' => 123, 'name' => 'John Doe')
1110 * $sql = 'SELECT `id`, `name` FROM `user`';
1111 * $users = PMA_DBI_fetch_result($sql, 0);
1113 * // $users['123'] = array(0 => 123, 1 => 'John Doe')
1115 * $sql = 'SELECT `id`, `name` FROM `user`';
1116 * $users = PMA_DBI_fetch_result($sql, 'id', 'name');
1118 * $users = PMA_DBI_fetch_result($sql, 0, 1);
1120 * // $users['123'] = 'John Doe'
1122 * $sql = 'SELECT `name` FROM `user`';
1123 * $users = PMA_DBI_fetch_result($sql);
1125 * // $users[] = 'John Doe'
1127 * $sql = 'SELECT `group`, `name` FROM `user`'
1128 * $users = PMA_DBI_fetch_result($sql, array('group', null), 'name');
1130 * // $users['admin'][] = 'John Doe'
1132 * $sql = 'SELECT `group`, `name` FROM `user`'
1133 * $users = PMA_DBI_fetch_result($sql, array('group', 'name'), 'id');
1135 * // $users['admin']['John Doe'] = '123'
1140 * @uses PMA_DBI_try_query()
1141 * @uses PMA_DBI_num_rows()
1142 * @uses PMA_DBI_num_fields()
1143 * @uses PMA_DBI_fetch_row()
1144 * @uses PMA_DBI_fetch_assoc()
1145 * @uses PMA_DBI_free_result()
1146 * @param string|mysql_result $result query or mysql result
1147 * @param string|integer $key field-name or offset
1148 * used as key for array
1149 * @param string|integer $value value-name or offset
1150 * used as value for array
1151 * @param resource $link mysql link
1152 * @param mixed $options
1153 * @return array resultrows or values indexed by $key
1155 function PMA_DBI_fetch_result($result, $key = null, $value = null,
1156 $link = null, $options = 0)
1158 $resultrows = array();
1160 if (is_string($result)) {
1161 $result = PMA_DBI_try_query($result, $link, $options);
1164 // return empty array if result is empty or false
1169 $fetch_function = 'PMA_DBI_fetch_assoc';
1171 // no nested array if only one field is in result
1172 if (null === $key && 1 === PMA_DBI_num_fields($result)) {
1174 $fetch_function = 'PMA_DBI_fetch_row';
1177 // if $key is an integer use non associative mysql fetch function
1179 $fetch_function = 'PMA_DBI_fetch_row';
1182 if (null === $key && null === $value) {
1183 while ($row = $fetch_function($result)) {
1184 $resultrows[] = $row;
1186 } elseif (null === $key) {
1187 while ($row = $fetch_function($result)) {
1188 $resultrows[] = $row[$value];
1190 } elseif (null === $value) {
1191 if (is_array($key)) {
1192 while ($row = $fetch_function($result)) {
1193 $result_target =& $resultrows;
1194 foreach ($key as $key_index) {
1195 if (null === $key_index) {
1196 $result_target =& $result_target[];
1200 if (! isset($result_target[$row[$key_index]])) {
1201 $result_target[$row[$key_index]] = array();
1203 $result_target =& $result_target[$row[$key_index]];
1205 $result_target = $row;
1208 while ($row = $fetch_function($result)) {
1209 $resultrows[$row[$key]] = $row;
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[$value];
1230 while ($row = $fetch_function($result)) {
1231 $resultrows[$row[$key]] = $row[$value];
1236 PMA_DBI_free_result($result);
1241 * return default table engine for given database
1243 * @return string default table engine
1245 function PMA_DBI_get_default_engine()
1247 return PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
1251 * Get supported SQL compatibility modes
1253 * @return array supported SQL compatibility modes
1255 function PMA_DBI_getCompatibilities()
1257 $compats = array('NONE');
1258 $compats[] = 'ANSI';
1260 $compats[] = 'MAXDB';
1261 $compats[] = 'MYSQL323';
1262 $compats[] = 'MYSQL40';
1263 $compats[] = 'MSSQL';
1264 $compats[] = 'ORACLE';
1265 // removed; in MySQL 5.0.33, this produces exports that
1266 // can't be read by POSTGRESQL (see our bug #1596328)
1267 //$compats[] = 'POSTGRESQL';
1268 $compats[] = 'TRADITIONAL';
1274 * returns warnings for last query
1276 * @uses $GLOBALS['userlink']
1277 * @uses PMA_DBI_fetch_result()
1278 * @param resource mysql link $link mysql link resource
1279 * @return array warnings
1281 function PMA_DBI_get_warnings($link = null)
1284 if (isset($GLOBALS['userlink'])) {
1285 $link = $GLOBALS['userlink'];
1291 return PMA_DBI_fetch_result('SHOW WARNINGS', null, null, $link);
1295 * returns true (int > 0) if current user is superuser
1298 * @uses $_SESSION['is_superuser'] for caching
1299 * @uses $GLOBALS['userlink']
1300 * @uses $GLOBALS['server']
1301 * @uses PMA_DBI_try_query()
1302 * @uses PMA_DBI_QUERY_STORE
1303 * @return integer $is_superuser
1305 function PMA_isSuperuser()
1307 if (PMA_cacheExists('is_superuser', true)) {
1308 return PMA_cacheGet('is_superuser', true);
1311 // with mysql extension, when connection failed we don't have
1313 if (isset($GLOBALS['userlink'])) {
1314 $r = (bool) PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', $GLOBALS['userlink'], PMA_DBI_QUERY_STORE
);
1315 PMA_cacheSet('is_superuser', $r, true);
1317 PMA_cacheSet('is_superuser', false, true);
1320 return PMA_cacheGet('is_superuser', true);
1324 * returns an array of PROCEDURE or FUNCTION names for a db
1326 * @uses PMA_DBI_free_result()
1327 * @param string $db db name
1328 * @param string $which PROCEDURE | FUNCTION
1329 * @param resource $link mysql link
1331 * @return array the procedure names or function names
1333 function PMA_DBI_get_procedures_or_functions($db, $which, $link = null)
1335 $shows = PMA_DBI_fetch_result('SHOW ' . $which . ' STATUS;', null, null, $link);
1337 foreach ($shows as $one_show) {
1338 if ($one_show['Db'] == $db && $one_show['Type'] == $which) {
1339 $result[] = $one_show['Name'];
1346 * returns the definition of a specific PROCEDURE, FUNCTION or EVENT
1348 * @uses PMA_DBI_fetch_value()
1349 * @param string $db db name
1350 * @param string $which PROCEDURE | FUNCTION | EVENT
1351 * @param string $name the procedure|function|event name
1352 * @param resource $link mysql link
1354 * @return string the definition
1356 function PMA_DBI_get_definition($db, $which, $name, $link = null)
1358 $returned_field = array(
1359 'PROCEDURE' => 'Create Procedure',
1360 'FUNCTION' => 'Create Function',
1361 'EVENT' => 'Create Event'
1363 $query = 'SHOW CREATE ' . $which . ' ' . PMA_backquote($db) . '.' . PMA_backquote($name);
1364 return(PMA_DBI_fetch_value($query, 0, $returned_field[$which]));
1368 * returns details about the TRIGGERs of a specific table
1370 * @uses PMA_DBI_fetch_result()
1371 * @param string $db db name
1372 * @param string $table table name
1373 * @param string $delimiter the delimiter to use (may be empty)
1375 * @return array information about triggers (may be empty)
1377 function PMA_DBI_get_triggers($db, $table, $delimiter = '//')
1381 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
1382 // Note: in http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html
1383 // their example uses WHERE TRIGGER_SCHEMA='dbname' so let's use this
1384 // instead of WHERE EVENT_OBJECT_SCHEMA='dbname'
1385 $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) . "';");
1387 $triggers = PMA_DBI_fetch_result("SHOW TRIGGERS FROM " . PMA_backquote(PMA_sqlAddslashes($db,true)) . " LIKE '" . PMA_sqlAddslashes($table, true) . "';");
1391 foreach ($triggers as $trigger) {
1392 if ($GLOBALS['cfg']['Server']['DisableIS']) {
1393 $trigger['TRIGGER_NAME'] = $trigger['Trigger'];
1394 $trigger['ACTION_TIMING'] = $trigger['Timing'];
1395 $trigger['EVENT_MANIPULATION'] = $trigger['Event'];
1396 $trigger['EVENT_OBJECT_TABLE'] = $trigger['Table'];
1397 $trigger['ACTION_STATEMENT'] = $trigger['Statement'];
1399 $one_result = array();
1400 $one_result['name'] = $trigger['TRIGGER_NAME'];
1401 $one_result['action_timing'] = $trigger['ACTION_TIMING'];
1402 $one_result['event_manipulation'] = $trigger['EVENT_MANIPULATION'];
1404 // do not prepend the schema name; this way, importing the
1405 // definition into another schema will work
1406 $one_result['full_trigger_name'] = PMA_backquote($trigger['TRIGGER_NAME']);
1407 $one_result['drop'] = 'DROP TRIGGER IF EXISTS ' . $one_result['full_trigger_name'];
1408 $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";
1410 $result[] = $one_result;
1417 * Returns TRUE if $db.$view_name is a view, FALSE if not
1419 * @uses PMA_DBI_fetch_result()
1420 * @param string $db database name
1421 * @param string $view_name view/table name
1423 * @return bool TRUE if $db.$view_name is a view, FALSE if not
1425 function PMA_isView($db, $view_name)
1427 $result = PMA_DBI_fetch_result("SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$db."' and TABLE_NAME = '".$view_name."';");