What are common syntax errors when connecting to a database in PHP?

Common syntax errors when connecting to a database in PHP include missing semicolons at the end of statements, incorrect quotes or quotation marks, and using the wrong database credentials. To solve these issues, make sure to double-check your syntax, especially the quotes and semicolons, and ensure that the database credentials are correct.

// Correcting syntax errors when connecting to a database in PHP

$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "myDB";

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

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