query("SELECT * FROM statistics"); $sales_data = array(); while($row = $result->fetch_assoc()) { $sales_data[] = $row; } $db->close(); ?>
selectCollection('website_analytics', 'statistics'); $cursor = $collection->find(); $website_stats = array(); foreach ($cursor as $doc) { $website_stats[] = $doc; } ?>In this example, we retrieve a statistics table from a MongoDB database using the official MongoDB PHP library. We store the statistics in the $website_stats array. Package/library used: For the first example, we used the built-in PHP mysqli extension to interact with a MySQL database. For the second example, we used the official MongoDB PHP library to interact with a MongoDB database.