随着NoSQL数据库管理系统的普及,很多软件的数据存储都转向MongoDB数据库。它采用动态模式将数据转化为结构化的JSON文档存储,提高html' target='_blank'>应用程序性能。
<?php$mongo = new Mongo();$db = $mongo->selectDB(“test”);?>
<?php$mongo = new Mongo(“mongodb://{$username}:{$password}@{$host}”);$db = $mongo->selectDB(“test”);?>
//获取数据库列表$mongo->admin->command(array(“listDatabases” => 1));//获取test数据库的表$db->listCollections();
db.listDatabasesdb.test.showCollections
<?php$people = $db->people;$insert = array(“user” => “demo@uncletoo.com”, “password” => md5(“demo_password”));$db->insert($insert);?>
<?php$update = array(“$set” => array(“user” => “demo@9lessons.info”));$where = array(“password” => “password”);$people->update($where,$update);?>
<form action="index.php" method="POST">Email:<input type="text" id="usr_email" name="usr_email" />Password:<input type="password" id="usr_password" name="usr_password" /><input name="submitForm" id="submitForm" type="submit" value="Login" /></form>
<?php$succss = "";if(isset($_POST) and $_POST['submitForm'] == "Login" ){$usr_email = mysql_escape_string($_POST['usr_email']);$usr_password = mysql_escape_string($_POST['usr_password']);$error = array();// Email Validationif(empty($usr_email) or !filter_var($usr_email,FILTER_SANITIZE_EMAIL)){$error[] = "Empty or invalid email address";}if(empty($usr_password)){$error[] = "Enter your password";}if(count($error) == 0){$con = new Mongo();if($con){// Select Database$db = $con->test;// Select Collection$people = $db->people;$qry = array("user" => $usr_email,"password" => md5($usr_password));$result = $people->findOne($qry);if($result){$success = "You are successully loggedIn";// Rest of code up to you....}} else {die("Mongo DB not installed");}}}?>
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答