1、使用 MySQL 创建数据表
语法:
CREATE TABLE table_name (column_name column_type);
举例:在 RUNOOB 数据库中创建数据表 runoob_tbl:文章源自十年又十年-https://www.bbigsun.com/239.html
CREATE TABLE IF NOT EXISTS runoob_tbl
(
runoob_id
INT UNSIGNED AUTO_INCREMENT,
runoob_title
VARCHAR(100) NOT NULL,
runoob_author
VARCHAR(40) NOT NULL,
submission_date
DATE,
PRIMARY KEY ( runoob_id
)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
2、使用 PHP 创建数据表
PHP 使用 mysqli_query() 函数来操作 MySQL 数据表。文章源自十年又十年-https://www.bbigsun.com/239.html
<?php
$dbhost = 'localhost'; // mysql服务器主机地址
$dbuser = 'root'; // mysql用户名
$dbpass = '123456'; // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接失败: ' . mysqli_error($conn));
}
echo '连接成功<br />';
$sql = "CREATE TABLE runoob_tbl( ".
"runoob_id INT NOT NULL AUTO_INCREMENT, ".
"runoob_title VARCHAR(100) NOT NULL, ".
"runoob_author VARCHAR(40) NOT NULL, ".
"submission_date DATE, ".
"PRIMARY KEY ( runoob_id ))ENGINE=InnoDB DEFAULT CHARSET=utf8; ";
mysqli_select_db( $conn, 'RUNOOB' );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die('数据表创建失败: ' . mysqli_error($conn));
}
echo "数据表创建成功\n";
mysqli_close($conn);
?>
文章源自十年又十年-https://www.bbigsun.com/239.html文章源自十年又十年-https://www.bbigsun.com/239.html 纸上得来终觉浅,绝知此事要躬行。
17688689121
我的微信
微信扫一扫
评论