Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / tbl_create.php
blobc37c351323ffbd29fc68e04840ed7a1bcd1f562a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays table create form and handles it
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\URL;
10 /**
11 * Get some core libraries
13 require_once 'libraries/common.inc.php';
14 require_once 'libraries/create_addfield.lib.php';
16 // Check parameters
17 PMA\libraries\Util::checkParameters(array('db'));
19 /* Check if database name is empty */
20 if (strlen($db) === 0) {
21 PMA\libraries\Util::mysqlDie(
22 __('The database name is empty!'), '', false, 'index.php'
26 /**
27 * Selects the database to work with
29 if (!$GLOBALS['dbi']->selectDb($db)) {
30 PMA\libraries\Util::mysqlDie(
31 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
32 '',
33 false,
34 'index.php'
38 if ($GLOBALS['dbi']->getColumns($db, $table)) {
39 // table exists already
40 PMA\libraries\Util::mysqlDie(
41 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
42 '',
43 false,
44 'db_structure.php' . URL::getCommon(array('db' => $db))
48 // for libraries/tbl_columns_definition_form.inc.php
49 // check number of fields to be created
50 $num_fields = PMA_getNumberOfFieldsFromRequest();
52 $action = 'tbl_create.php';
54 /**
55 * The form used to define the structure of the table has been submitted
57 if (isset($_REQUEST['do_save_data'])) {
58 $sql_query = PMA_getTableCreationQuery($db, $table);
60 // If there is a request for SQL previewing.
61 if (isset($_REQUEST['preview_sql'])) {
62 PMA_previewSQL($sql_query);
64 // Executes the query
65 $result = $GLOBALS['dbi']->tryQuery($sql_query);
67 if ($result) {
68 // If comments were sent, enable relation stuff
69 include_once 'libraries/transformations.lib.php';
70 // Update comment table for mime types [MIME]
71 if (isset($_REQUEST['field_mimetype'])
72 && is_array($_REQUEST['field_mimetype'])
73 && $cfg['BrowseMIME']
74 ) {
75 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
76 if (isset($_REQUEST['field_name'][$fieldindex])
77 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
78 ) {
79 PMA_setMIME(
80 $db, $table,
81 $_REQUEST['field_name'][$fieldindex], $mimetype,
82 $_REQUEST['field_transformation'][$fieldindex],
83 $_REQUEST['field_transformation_options'][$fieldindex],
84 $_REQUEST['field_input_transformation'][$fieldindex],
85 $_REQUEST['field_input_transformation_options'][$fieldindex]
90 } else {
91 $response = PMA\libraries\Response::getInstance();
92 $response->setRequestStatus(false);
93 $response->addJSON('message', $GLOBALS['dbi']->getError());
95 exit;
96 } // end do create table
98 //This global variable needs to be reset for the headerclass to function properly
99 $GLOBAL['table'] = '';
102 * Displays the form used to define the structure of the table
104 require 'libraries/tbl_columns_definition_form.inc.php';