Questions
nicolez4nicolez4asked 4 months ago
I want to know about how to connect to MySQL database in PHP localhost?
1

1 Answers

Accepted
codegenlabcodegenlabanswered 4 months ago
Following code will show you how to connect to MySQL database in PHP.
//php code srtart
$servername = "localhost";
$database = "database"; //database name
$username = "username"; //mysql database username
$password = "password"; //mysql database password

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection status
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}

echo “Connected successfully”;  // if database connect you will get this message

mysqli_close($conn); //close connection
//php code end
1