What potential security risks are involved in using the deprecated mysql_* functions in PHP?

Using deprecated mysql_* functions in PHP can lead to security risks such as SQL injection attacks, as these functions do not provide adequate protection against malicious input. To mitigate this risk, it is recommended to switch to using MySQLi or PDO for database interactions, as they offer prepared statements and parameterized queries to prevent SQL injection.

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

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

// Use prepared statements to prevent SQL injection
$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$username = "example_user";
$stmt->execute();
$result = $stmt->get_result();

// Fetch data from the result set
while ($row = $result->fetch_assoc()) {
    // Process the data
}

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