What are the potential benefits of using MySQL and full-text search instead of handling multiple text files?

Using MySQL and full-text search can provide benefits such as faster search queries, better scalability, easier management of data, and the ability to perform complex search operations. By storing text data in a database like MySQL and utilizing its full-text search capabilities, you can streamline the search process and improve overall performance.

// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "mydatabase";

$conn = new mysqli($servername, $username, $password, $dbname);

// Perform full-text search query
$search_term = "example";
$sql = "SELECT * FROM mytable WHERE MATCH(column_name) AGAINST ('$search_term' IN NATURAL LANGUAGE MODE)";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
    }
} else {
    echo "0 results found";
}

$conn->close();