What are the potential risks of using mysql_query and SELECT * in PHP code?

Using mysql_query and SELECT * in PHP code can pose security risks such as SQL injection attacks and performance issues due to fetching unnecessary data. It is recommended to use parameterized queries and specify the columns explicitly in the SELECT statement to mitigate these risks.

// Using parameterized query and specifying columns explicitly
$conn = mysqli_connect("localhost", "username", "password", "database");

$query = "SELECT column1, column2 FROM table WHERE condition = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("s", $condition);
$stmt->execute();
$result = $stmt->get_result();

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

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