What are the advantages of using the MySQLi extension over the MySQL extension in PHP?

The MySQLi extension in PHP offers several advantages over the older MySQL extension, including support for prepared statements, improved security features, and better performance. It is recommended to use MySQLi for new projects as the MySQL extension is deprecated and no longer maintained.

// Using MySQLi extension to connect to a MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "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";