What best practices should be followed when transitioning from the mysql extension to the mysqli extension in PHP?

When transitioning from the mysql extension to the mysqli extension in PHP, it is important to update your code to use the improved security features and functionalities offered by mysqli. This includes using prepared statements to prevent SQL injection attacks, utilizing object-oriented style programming, and updating function calls to the mysqli equivalents.

// Before transitioning from mysql to mysqli
$connection = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database', $connection);
$result = mysql_query('SELECT * FROM table', $connection);

// After transitioning to mysqli
$connection = mysqli_connect('localhost', 'username', 'password', 'database');
$result = mysqli_query($connection, 'SELECT * FROM table');