<?php
// 此路径应指向 Composer 的自动加载器
require 'vendor/autoload.php';
<?php
require 'vendor/autoload.php'; // 包含 Composer 的自动加载器
$client = new MongoDB\Client("mongodb://127.0.0.1:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>
<?php
require 'vendor/autoload.php'; // 包含 Composer 的自动加载器
$client = new MongoDB\Client("mongodb://127.0.0.1:27017");
$collection = $client->demo->beers;
$result = $collection->find( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
foreach ($result as $entry) {
echo $entry['_id'], ': ', $entry['name'], "\n";
}
?>