php创建数数据表的简单实现

php创建数数据表的简单实现


DATE: 2017-09-18 17:06:40

代码参考自http://www.runoob.com/php/php-mysql-create-table.html

<?php

//mysql
$servername = "localhost";
$username = "root";
$password = "****";
$dbname = "****";

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

if ($conn->connect_error) {
        die("Connect Failed: " . $conn->connect_error);
}

echo "Connected Success!";

// use sql create database table
$sql = "create table guests (
        id int(6) unsigned auto_increment primary key,
        name varchar(30) not null,
        email varchar(50),
        reg_date timestamp)";

if ($conn->query($sql) === true) {
        echo "Table guests created Successfully";
} else {
        echo "Create Error: " . $conn->error;
}

$conn->close();

?>

执行结果如下:

这里写图片描述

版权声明

弈心博客


本文首发site_name,转载请附上博文链接!