2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays table create form and handles it
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config
;
12 use PhpMyAdmin\CreateAddField
;
13 use PhpMyAdmin\DatabaseInterface
;
14 use PhpMyAdmin\Response
;
15 use PhpMyAdmin\Transformations
;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
23 require_once ROOT_PATH
. 'libraries/common.inc.php';
25 /** @var Response $response */
26 $response = $containerBuilder->get(Response
::class);
28 /** @var DatabaseInterface $dbi */
29 $dbi = $containerBuilder->get(DatabaseInterface
::class);
32 Util
::checkParameters(['db']);
34 /** @var Transformations $transformations */
35 $transformations = $containerBuilder->get('transformations');
37 /** @var string $db */
38 $db = $containerBuilder->getParameter('db');
40 /** @var string $table */
41 $table = $containerBuilder->getParameter('table');
43 /** @var Config $config */
44 $config = $containerBuilder->get('config');
45 $cfg = $config->settings
;
47 /* Check if database name is empty */
48 if (strlen($db) === 0) {
50 __('The database name is empty!'),
58 * Selects the database to work with
60 if (! $dbi->selectDb($db)) {
62 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
69 if ($dbi->getColumns($db, $table)) {
70 // table exists already
72 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
75 'db_structure.php' . Url
::getCommon(['db' => $db])
79 $createAddField = new CreateAddField($dbi);
81 // for libraries/tbl_columns_definition_form.inc.php
82 // check number of fields to be created
83 $num_fields = $createAddField->getNumberOfFieldsFromRequest();
85 $action = 'tbl_create.php';
88 * The form used to define the structure of the table has been submitted
90 if (isset($_POST['do_save_data'])) {
91 // lower_case_table_names=1 `DB` becomes `db`
92 if ($dbi->getLowerCaseNames() === '1') {
96 $table = mb_strtolower(
100 $sql_query = $createAddField->getTableCreationQuery($db, $table);
102 // If there is a request for SQL previewing.
103 if (isset($_POST['preview_sql'])) {
104 Core
::previewSQL($sql_query);
106 // Executes the query
107 $result = $dbi->tryQuery($sql_query);
110 // Update comment table for mime types [MIME]
111 if (isset($_POST['field_mimetype'])
112 && is_array($_POST['field_mimetype'])
113 && $cfg['BrowseMIME']
115 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
116 if (isset($_POST['field_name'][$fieldindex])
117 && strlen($_POST['field_name'][$fieldindex]) > 0
119 $transformations->setMime(
122 $_POST['field_name'][$fieldindex],
124 $_POST['field_transformation'][$fieldindex],
125 $_POST['field_transformation_options'][$fieldindex],
126 $_POST['field_input_transformation'][$fieldindex],
127 $_POST['field_input_transformation_options'][$fieldindex]
133 $response->setRequestStatus(false);
134 $response->addJSON('message', $dbi->getError());
137 } // end do create table
139 //This global variable needs to be reset for the headerclass to function properly
140 $GLOBAL['table'] = '';
143 * Displays the form used to define the structure of the table
145 require ROOT_PATH
. 'libraries/tbl_columns_definition_form.inc.php';