What are the potential risks of using outdated MySQL functions in PHP code?

Using outdated MySQL functions in PHP code can pose security risks as these functions may be deprecated and no longer receive updates or support from the community. This can leave your application vulnerable to SQL injection attacks and other security threats. To mitigate this risk, it is recommended to use modern MySQLi or PDO functions for database interactions in PHP.

// 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();

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

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