What are the security concerns associated with using mysql_ functions in PHP?

Using mysql_ functions in PHP poses security concerns due to their vulnerability to SQL injection attacks. To address this issue, it is recommended to use parameterized queries or prepared statements with mysqli or PDO extensions in PHP.

// Example of using prepared statements with mysqli to prevent SQL injection
$mysqli = new mysqli("localhost", "username", "password", "database");

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

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

// Set parameters and execute
$username = "example_username";
$stmt->execute();

// Get the result
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    echo "Username: " . $row['username'];
}

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