What are common syntax errors to watch out for when using PHP to connect to a database?

Common syntax errors when connecting to a database in PHP include missing semicolons at the end of lines, incorrect variable names, and mismatched quotation marks. To avoid these errors, double-check your code for typos and ensure that all syntax is correct.

// Correct syntax for connecting to a database in PHP
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

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

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