(面向过程)
<?php
//创建连接
$servername = "localhost"; //域名
$username = "root"; //用户名
$passwd = ""; //密码
//检测连接
$conn = mysqli_connect($servername,$username,$passwd);
if(!$conn){
die("connection failed:" . mysqli_connect_errno());
}else{
echo "成功连接数据库";
mysqli_close($conn); //关闭连接
}
?>