What is the difference between using a SELECT statement in MySQL and an if condition in PHP to filter data based on a specific character?

When filtering data based on a specific character, using a SELECT statement in MySQL is more efficient as it directly queries the database for the desired data. On the other hand, using an if condition in PHP would involve retrieving all data from the database and then filtering it in PHP code, which can be slower and consume more resources.

// Using a SELECT statement in MySQL to filter data based on a specific character
$query = "SELECT * FROM table_name WHERE column_name LIKE '%specific_character%'";
$result = mysqli_query($connection, $query);

// Fetch and display the filtered data
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['column_name'];
}