What are the key differences between the deprecated mysql_* functions and the mysqli_* functions in PHP when interacting with a MySQL database?

The key differences between the deprecated mysql_* functions and the mysqli_* functions in PHP are that mysqli_* functions support prepared statements, transactions, and stored procedures, which provide better security and performance compared to the older mysql_* functions. It is recommended to switch to mysqli_* or PDO for interacting with a MySQL database in PHP to ensure compatibility with newer versions of PHP and MySQL.

// Using mysqli_* functions to connect to a MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Perform a query using prepared statement
$stmt = $mysqli->prepare("SELECT id, name FROM users WHERE id = ?");
$stmt->bind_param("i", $userId);
$userId = 1;
$stmt->execute();
$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
    echo "ID: " . $row['id'] . " Name: " . $row['name'] . "<br>";
}

$stmt->close();
$mysqli->close();