What are the best practices for transitioning from "mysql" to "mysqli" in existing PHP code?

When transitioning from "mysql" to "mysqli" in existing PHP code, the main changes involve updating the connection method and query execution. It is important to replace deprecated "mysql_" functions with their "mysqli_" equivalents and ensure proper error handling. Additionally, parameterized queries should be used to prevent SQL injection vulnerabilities.

// Before transitioning from "mysql" to "mysqli"
$connection = mysql_connect($servername, $username, $password);
mysql_select_db($database, $connection);
$result = mysql_query($query);

// After transitioning to "mysqli"
$connection = mysqli_connect($servername, $username, $password, $database);
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}
$result = mysqli_query($connection, $query);
if (!$result) {
    die("Query failed: " . mysqli_error($connection));
}