How do I connect to MySQL

Connecting to a MySQL database in PHP is straightforward. Below is an example demonstrating how to establish a connection to a MySQL database using the MySQLi extension.

<?php $servername = "localhost"; $username = "your_username"; $password = "your_password"; $dbname = "your_database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>

MySQL PHP database connection MySQLi