What are the differences between using mysqli_connect and mysql_connect in PHP for database connections?

The main difference between using mysqli_connect and mysql_connect in PHP for database connections is that mysqli_connect is the improved version of mysql_connect and supports the use of prepared statements, transactions, and other advanced features. It is recommended to use mysqli_connect for better security and performance.

// Using mysqli_connect for database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}