What is the difference between SQL and MySQL in terms of using PHP to connect to a database?

The main difference between SQL and MySQL is that SQL is a query language used to interact with databases in general, while MySQL is a specific relational database management system that uses SQL. When connecting to a MySQL database using PHP, you need to use the MySQLi or PDO extension in PHP to establish a connection and perform queries.

// Using MySQLi extension to connect to a MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$database = "dbname";

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

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

echo "Connected successfully";