What are the best practices for migrating code from PHP4 to PHP5 to ensure compatibility and security?

When migrating code from PHP4 to PHP5, it is important to update deprecated functions, syntax, and features to ensure compatibility and security. This includes replacing functions like "mysql_" with "mysqli_" for database interactions, updating object-oriented programming syntax, and addressing any security vulnerabilities present in the code.

// Example of updating database connection from mysql_ to mysqli_
// PHP4
$connection = mysql_connect($host, $username, $password);
$db_selected = mysql_select_db($database, $connection);

// PHP5
$connection = mysqli_connect($host, $username, $password, $database);
if (!$connection) {
    die('Connection failed: ' . mysqli_connect_error());
}