What are the differences between using mysql and mysqli functions in PHP, and how do they impact code compatibility?

When migrating from mysql functions to mysqli functions in PHP, the main differences lie in the improved security features and support for prepared statements in mysqli. To ensure code compatibility, you need to update all mysql functions to their mysqli equivalents. This can involve changing function names, parameter order, and syntax.

// Before: Using mysql functions
$link = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database', $link);
$result = mysql_query('SELECT * FROM table', $link);

// After: Using mysqli functions
$link = mysqli_connect('localhost', 'username', 'password', 'database');
$result = mysqli_query($link, 'SELECT * FROM table');