What are the advantages and disadvantages of using the mysqli extension over the mysql extension in PHP?

The mysqli extension in PHP offers several advantages over the mysql extension, such as support for prepared statements, improved security with parameterized queries, and support for transactions. However, the mysqli extension requires a different syntax compared to the mysql extension, which may require some code changes when migrating from mysql to mysqli.

// Connect to MySQL database using mysqli extension
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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