How can one migrate from using mysql_* functions to more modern alternatives like mysqli or PDO in PHP?

To migrate from using mysql_* functions to more modern alternatives like mysqli or PDO in PHP, you need to update your code to use the newer functions provided by mysqli or PDO. This involves making changes to your database connection code, query execution, and result handling.

// Before migration
$conn = mysql_connect("localhost", "username", "password");
mysql_select_db("database", $conn);
$result = mysql_query("SELECT * FROM table");

// After migration to mysqli
$conn = mysqli_connect("localhost", "username", "password", "database");
$result = mysqli_query($conn, "SELECT * FROM table");

// After migration to PDO
$dsn = 'mysql:host=localhost;dbname=database';
$username = 'username';
$password = 'password';
$conn = new PDO($dsn, $username, $password);
$stmt = $conn->query("SELECT * FROM table");