Translated using Weblate (Chinese (Traditional))
[phpmyadmin.git] / tbl_create.php
blob503b168a325f5f2363ef8f58c9e91c51bb0fd2e2
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 $sql_query = $createAddField->getTableCreationQuery($db, $table);
67 // If there is a request for SQL previewing.
68 if (isset($_POST['preview_sql'])) {
69 Core::previewSQL($sql_query);
71 // Executes the query
72 $result = $GLOBALS['dbi']->tryQuery($sql_query);
74 if ($result) {
75 // Update comment table for mime types [MIME]
76 if (isset($_POST['field_mimetype'])
77 && is_array($_POST['field_mimetype'])
78 && $cfg['BrowseMIME']
79 ) {
80 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
81 if (isset($_POST['field_name'][$fieldindex])
82 && strlen($_POST['field_name'][$fieldindex]) > 0
83 ) {
84 Transformations::setMIME(
85 $db, $table,
86 $_POST['field_name'][$fieldindex], $mimetype,
87 $_POST['field_transformation'][$fieldindex],
88 $_POST['field_transformation_options'][$fieldindex],
89 $_POST['field_input_transformation'][$fieldindex],
90 $_POST['field_input_transformation_options'][$fieldindex]
95 } else {
96 $response = Response::getInstance();
97 $response->setRequestStatus(false);
98 $response->addJSON('message', $GLOBALS['dbi']->getError());
100 exit;
101 } // end do create table
103 //This global variable needs to be reset for the headerclass to function properly
104 $GLOBAL['table'] = '';
107 * Displays the form used to define the structure of the table
109 require 'libraries/tbl_columns_definition_form.inc.php';