Add ChangeLog entry for #14184
[phpmyadmin.git] / tbl_create.php
blob1d9c30cc3c477f81b0d4d547dcef0cb2a5ef3f20
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 */
9 use PhpMyAdmin\Core;
10 use PhpMyAdmin\CreateAddField;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Transformations;
13 use PhpMyAdmin\Url;
14 use PhpMyAdmin\Util;
16 /**
17 * Get some core libraries
19 require_once 'libraries/common.inc.php';
21 // Check parameters
22 Util::checkParameters(array('db'));
24 /* Check if database name is empty */
25 if (strlen($db) === 0) {
26 Util::mysqlDie(
27 __('The database name is empty!'), '', false, 'index.php'
31 /**
32 * Selects the database to work with
34 if (!$GLOBALS['dbi']->selectDb($db)) {
35 Util::mysqlDie(
36 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
37 '',
38 false,
39 'index.php'
43 if ($GLOBALS['dbi']->getColumns($db, $table)) {
44 // table exists already
45 Util::mysqlDie(
46 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
47 '',
48 false,
49 'db_structure.php' . Url::getCommon(array('db' => $db))
53 $createAddField = new CreateAddField($GLOBALS['dbi']);
55 // for libraries/tbl_columns_definition_form.inc.php
56 // check number of fields to be created
57 $num_fields = $createAddField->getNumberOfFieldsFromRequest();
59 $action = 'tbl_create.php';
61 /**
62 * The form used to define the structure of the table has been submitted
64 if (isset($_POST['do_save_data'])) {
65 // lower_case_table_names=1 `DB` becomes `db`
66 if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
67 $db = mb_strtolower(
68 $db
70 $table = mb_strtolower(
71 $table
74 $sql_query = $createAddField->getTableCreationQuery($db, $table);
76 // If there is a request for SQL previewing.
77 if (isset($_POST['preview_sql'])) {
78 Core::previewSQL($sql_query);
80 // Executes the query
81 $result = $GLOBALS['dbi']->tryQuery($sql_query);
83 if ($result) {
84 // Update comment table for mime types [MIME]
85 if (isset($_POST['field_mimetype'])
86 && is_array($_POST['field_mimetype'])
87 && $cfg['BrowseMIME']
88 ) {
89 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
90 if (isset($_POST['field_name'][$fieldindex])
91 && strlen($_POST['field_name'][$fieldindex]) > 0
92 ) {
93 Transformations::setMIME(
94 $db, $table,
95 $_POST['field_name'][$fieldindex], $mimetype,
96 $_POST['field_transformation'][$fieldindex],
97 $_POST['field_transformation_options'][$fieldindex],
98 $_POST['field_input_transformation'][$fieldindex],
99 $_POST['field_input_transformation_options'][$fieldindex]
104 } else {
105 $response = Response::getInstance();
106 $response->setRequestStatus(false);
107 $response->addJSON('message', $GLOBALS['dbi']->getError());
109 exit;
110 } // end do create table
112 //This global variable needs to be reset for the headerclass to function properly
113 $GLOBAL['table'] = '';
116 * Displays the form used to define the structure of the table
118 require 'libraries/tbl_columns_definition_form.inc.php';