What are the advantages of switching from mysql functions to mysqli functions for database connections in PHP?

Switching from mysql functions to mysqli functions in PHP for database connections offers several advantages such as improved security features, support for prepared statements which help prevent SQL injection attacks, and better performance due to the use of the improved MySQL extension. It is recommended to use mysqli functions for database connections in PHP to ensure better security and performance.

// Using mysqli functions for database connection
$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";