如何使用常量创建mysqli表?

时间:2018-07-17 07:20:34

标签: php database mysqli

我正在尝试使用mysqli创建一个表,并使用预定义的常量为其赋予前缀名称,但是如果您请检查代码并告诉我有什么问题,我无法使其正常工作。

<?php
$servername = "localhost";
$dbname = "users";
$username = "root";
$password = "";
define("TABLE_PREIX","xjk");

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// sql to create table
$sql = "CREATE TABLE ".TABLE_PREIX."-users (
        id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
        firstname VARCHAR(30) NOT NULL,
        lastname VARCHAR(30) NOT NULL,
        email VARCHAR(50),
        reg_date TIMESTAMP
        )";

if ($conn->query($sql) === TRUE) {
    echo "Table created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}
?>

编辑:

这是错误:

  

错误创建表:您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以在第1行的'-users(id INT(6)UNSIGNED AUTO_INCREMENT PRIMARY KEY,firstname VARCH)附近使用正确的语法

0 个答案:

没有答案