MySQL在数据库中创建表

时间:2017-11-18 03:17:22

标签: php mysql

我有一些代码,我试图使用PHP代码中包含的mySQL在数据库中创建一个表。我将在下面显示我的代码。我似乎无法让它工作,即使我在我的XAMPP面板上激活了MySQL,因此,显然有连接,创建表时会产生错误

<?php
$link = @mysqli_connect( 'localhost', 'root'); /* Open link to mysql database (making an attempt to make a connection to MySQL server */
if ($link) {  // If this succeeds, do the following lines
    $sql = "CREATE TABLE IF NOT EXISTS tableName
(
        muqID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        dateTIME DATETIME,
        taskTime FLOAT(4,2),
        useTime VARCHAR(60),
        usedM VARCHAR(40),
        freqRate VARCHAR(200),
        gender CHAR(1),
        age TINYINT UNSIGNED,
        email VARCHAR(100),
        comment VARCHAR(3000)
)";
    $result = mysqli_query ( $link, $sql );
    echo ($result ? 'table sql created successfully' : 'Error creating table') . ": $sql"; // If result is true then echo success, if false, echo fail. 
    mysqli_close($link); /* Close link to mysql database */
} else {  // Otherwise, if doesnt succeed then echo 
    echo 'Nothing happened';
}

0 个答案:

没有答案