数据库SQL查询
mysql -u <user> -p
设置数据库编码格式:
set names utf8;
MySQLi连接MySQL数据库
$servername = "localhost";
$username = "username";
$password = "password";
// 创建连接
$conn = mysqli_connect($servername, $username, $password);
// 检测连接
if (!$conn) {
die("连接失败: " . mysqli_connect_error());}
echo "连接成功";
?>
//用完关闭
mysqli_close($conn);
创建数据库
$sql = "CREATE DATABASE TestDB";
if (mysqli_query($conn, $sql)) {
echo "数据库创建成功";
} else {
echo "创建数据库失败: " . mysqli_error($conn);
}
显示数据库:show databases;
删除数据库:drop database TestDB;