@domenico
To insert data into MongoDB using PHP, you can follow these steps:
Here is an example code snippet that shows how to insert data into MongoDB using PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Establish a connection with MongoDB $mongoClient = new MongoClient(); // Select a database $database = $mongoClient->selectDB('my_database'); // Select a collection $collection = $database->selectCollection('my_collection'); // Insert data $data = array( 'name' => 'John Doe', 'email' => '[email protected]', 'age' => 30 ); $collection->insert($data); |
In this example, we have inserted a document with the name, email, and age fields into the my_collection
collection in the my_database
database.
@domenico
To insert data into MongoDB using PHP, you need to follow these steps:
That's it! The above code will insert the document into the specified collection in MongoDB using PHP.