How can I check if a MySQL table exists with PHP?

前端 未结 12 1606
小鲜肉
小鲜肉 2020-12-02 13:08

As simple in theory as it sounds I\'ve done a fair amount of research and am having trouble figuring this out.

How can I check if a MySQL table exists and if it does

12条回答
  •  有刺的猬
    2020-12-02 13:40

    ";
            $sql = "CREATE TABLE user(
                id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
                name VARCHAR(255)NOT NULL,
                email VARCHAR(255)NOT NULL,
                password VARCHAR(255) NOT NULL
                );";
            if(mysqli_query($connection,$sql)) {
                echo "Created user table";
            } else{
                echo "User table already exists";
            }
        } else {
            echo "error : DB isnot connected";
        } ?>
    

提交回复
热议问题