What are the differences between using MySQL and MySQLi functions in PHP for database connectivity?

When connecting to a MySQL database in PHP, there are two main methods: using the MySQL functions or the MySQLi functions. MySQLi (MySQL Improved) is an enhanced version of the original MySQL extension, offering improved security and additional features. It is recommended to use MySQLi functions for new projects as the original MySQL functions are deprecated.

// Using MySQLi functions for database connectivity
$servername = "localhost";
$username = "username";
$password = "password";
$database = "dbname";

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

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