MongoDB Connector/PHP

https://data-flair.training/blogs/mongodb-php-tutorial/

1. Make a Connection and Select a Database

For connecting to the MongoDB database you need to specify the name of the database, if the database does not exist then MongoDB will create it automatically.

examplesdb;
echo "Database examplesdb selected";
?>

2.Create a Collection

examplesdb;
  echo "Database examplesdb selected";
  $collection = $db->createCollection("examplescol");
  echo "Collection created succsessfully";
?>

3.Insert a Document

examplesdb;
  echo "Database examplesdb selected";
  $collection = $db->examplescol;
  echo "Collection selected succsessfully";

  $document = array( 
  "title" => "MongoDB", 
  "description" => "database", 
  "likes" => 100,
  "url" => "http://www.data-flair.training/mongodb/",
  "by" => "data flair"
 );

$collection->insert($document);
echo "Document inserted successfully";
?>

你可能感兴趣的:(MongoDB Connector/PHP)