Requirements :
- Basic Knowledge of MongoDB
- MongoDB Server
- PHP driver for MongoDB
Start the server:
1.In windows, go to cmd and navigate to bin folder in mongodb
installation location.
installation location.
2.Execute " mongod " command to start the server.
If you haven't installed mongodb server before.check my videos MongoDB installation in windows and php driver setup for mongodb
code:
Explanation :
$connection=new MongoClient();
MongoClient() by default creats a connection to server at localhost:27017.If you want to create a connection to remote server then you can specify it as arguments.
$db=$connection->university;
This piece of code selects the database named university.If the database haven't created before,mongodb will automaticaly creates a databse.
$student_collection= $db->student;
same as above line,but this line creats (if first time ) and also selects collection(table in RDMS) named student.you dont have to specify any schema ,mongodb has dynamic schema feature.
Finally,create an array with required fields.Insert created array (document) in to collection using insert() function.
Finally,create an array with required fields.Insert created array (document) in to collection using insert() function.
see actually use db works whereas Show Collections and db.student.find<> doesnt gives any output.....
ReplyDeletenice info...
ReplyDeleteHello YRR help .
ReplyDeleteI am unable to connect to PHP and Mongodb.
If you can help , that would be good.
Please reach to me to
sanpantech@outlook.com
hey, i want to insert entries which have been entered in my php sign up page into the mongodb database. so what do i do. please please help asap. thanks!
ReplyDeleteUncaught Error: Class 'MongoClient'
ReplyDelete