PHP connects to MySQL database

Check if the installation is successful

<?php
phpinfo()
?>

insert image description here

connect to MySQL

<?php
$servername = "localhost";
$username = "root";
$password = "";
 
// 创建连接
$conn = new mysqli($servername, $username, $password);
 
// 检测连接
if ($conn->connect_error) {
    
       
    
    die("连接失败: " . $conn->connect_error);
} 
echo "连接成功";
?>

Lines 2 to 4 must correspond to your own. If you don't know the user password, you can check it under the account. I chose the default root account . The
insert image description here
connection is successful:
insert image description here