标签:base ror var die mysqli 数据库 ret creat connect
连接数据库
$db = new MySQLi(‘localhost‘,‘root‘,‘root‘,‘z_1031‘);
!mysqli_connect_error() or die(‘连接失败‘);
$db->query(‘set names utf8‘);
return $db;
创建数据库
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "数据库创建成功";
} else {
echo "Error creating database: " . $conn->error;
}
创建 MySQL 表
使用use myDB 来选择要操作的数据库:
use myDB;
创建"MyGuests" 的表,5个列: "id", "firstname", "lastname", "email" 和 "reg_date":
CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)
标签:base ror var die mysqli 数据库 ret creat connect
原文地址:https://www.cnblogs.com/wjwap/p/10296543.html