What are the recommended best practices for migrating from mysql_ to mysqli_ functions in PHP scripts?
When migrating from `mysql_` to `mysqli_` functions in PHP scripts, it is important to update all database connection and query functions to use `mysqli_` functions for improved security and compatibility with newer PHP versions. This involves changing functions like `mysql_connect()` to `mysqli_connect()` and `mysql_query()` to `mysqli_query()`. Additionally, it is recommended to use prepared statements with `mysqli` to prevent SQL injection attacks.
// Before migration
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database', $conn);
$result = mysql_query('SELECT * FROM table', $conn);
// After migration
$conn = mysqli_connect('localhost', 'username', 'password', 'database');
$result = mysqli_query($conn, 'SELECT * FROM table');