What is the purpose of using a full-text index in a MySQL table?

A full-text index in a MySQL table allows for efficient searching of text data within a column. This can greatly improve the performance of searches on large text fields, such as in a blog post or product description. By creating a full-text index, MySQL can quickly locate relevant rows based on keywords or phrases, making searches faster and more accurate.

// Create a full-text index on the 'content' column of the 'posts' table
$sql = "CREATE FULLTEXT INDEX idx_content ON posts(content)";
$result = mysqli_query($conn, $sql);

if($result) {
    echo "Full-text index created successfully";
} else {
    echo "Error creating full-text index: " . mysqli_error($conn);
}