What are the potential risks of using the outdated mysql_* functions in PHP and how can developers transition to more secure options?

Using the outdated mysql_* functions in PHP poses security risks such as SQL injection vulnerabilities and lack of support for newer MySQL features. To transition to more secure options, developers should switch to using mysqli or PDO for database operations.

// Connect to MySQL using mysqli
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Perform a query using prepared statements
$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();

// Process the results
while ($row = $result->fetch_assoc()) {
    // Do something with the data
}

// Close the connection
$mysqli->close();