What are the potential security risks associated with using the mysql_ functions in PHP for database queries?

The mysql_ functions in PHP are deprecated and no longer recommended for use due to security vulnerabilities such as SQL injection attacks. To mitigate this risk, it is recommended to switch to using mysqli or PDO functions which support prepared statements to prevent SQL injection.

// Using mysqli prepared statements to query the database securely
$mysqli = new mysqli("localhost", "username", "password", "database");

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

$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);

$username = "example";
$stmt->execute();

$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
    // Process results
}

$stmt->close();
$mysqli->close();