How can database integration be utilized to store and retrieve specific article information in PHP applications using SimplePie?

Database integration can be utilized to store and retrieve specific article information in PHP applications using SimplePie by creating a database table to store the article data, establishing a connection to the database, inserting the article information into the database when fetching feed data with SimplePie, and querying the database to retrieve specific article information based on user input or criteria.

// Establish a connection to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "articles_db";

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

// Insert article information into the database when fetching feed data with SimplePie
$feed = new SimplePie();
$feed->set_feed_url('http://example.com/feed');
$feed->init();
$feed->handle_content_type();

foreach ($feed->get_items() as $item) {
    $title = $conn->real_escape_string($item->get_title());
    $content = $conn->real_escape_string($item->get_content());
    
    $sql = "INSERT INTO articles (title, content) VALUES ('$title', '$content')";
    $conn->query($sql);
}

// Query the database to retrieve specific article information based on user input or criteria
$search_query = "keyword";
$sql = "SELECT * FROM articles WHERE title LIKE '%$search_query%' OR content LIKE '%$search_query%'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "Title: " . $row['title'] . "<br>";
        echo "Content: " . $row['content'] . "<br><br>";
    }
} else {
    echo "No articles found.";
}

$conn->close();