What is the purpose of using regex in PHP for database search queries?

Using regex in PHP for database search queries allows for more flexible and powerful search patterns. It allows you to search for specific patterns or sequences of characters within your database data, making it easier to find relevant information. This can be especially useful when searching for data that may not have an exact match or when you need to search for data based on a specific pattern.

$searchTerm = $_GET['search_term'];
$query = "SELECT * FROM table_name WHERE column_name REGEXP '$searchTerm'";
$result = mysqli_query($connection, $query);

// Process the results
while ($row = mysqli_fetch_assoc($result)) {
    // Handle each row of data
}