官方文档地址:https://github.com/bmob/bmob-php-sdk
BmobConfig.class.php 配置文件
<?php
/**
* bmobConfig 配置文件
* @author newjueqi
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
*/
class BmobConfig
{
const APPID = '6b38962205813579cd8bccccd1c****'; //后台"应用密钥"中的Application ID
const RESTKEY = 'ee4f3b12eee9df0e28a730f991b****'; //后台"应用密钥"中的REST API Key
const BMOBURL = 'https://api.bmob.cn/1/'; //请勿修改
const BMOBURLTWO = 'https://api.bmob.cn/2/'; //请勿修改
}
<?php
include_once 'lib/BmobObject.class.php';
include_once 'lib/BmobUser.class.php';
$content = isset($_POST['content']) ? $_POST['content'] : '';
// echo $content;
try {
BmobUser 的例子 - -用户的登录与注册
$bmobUser = new BmobUser();
//用户注册, 其中username和password为必填字段
$res = $bmobUser->register(array("username"=>"cooldude095", "password"=>"dq095", "phone"=>"415-392-0202", "email"=>"bmobtest095@126.com"));
// object(stdClass)#2 (3) {
// ["createdAt"]=> string(19) "2018-09-12 23:15:28"
// ["objectId"]=> string(10) "67c9ced91d"
// ["sessionToken"]=> string(32) "8eb2d1a040611bfc804424ab20c01d14"
// }
//用户登录, 第一个参数为用户名,第二个参数为密码
$res = $bmobUser->login("cooldude095","dq095");
//object(stdClass)#2 (7) {
// ["createdAt"]=> string(19) "2018-09-12 23:15:28"
// ["email"]=> string(19) "bmobtest095@126.com"
// ["objectId"]=> string(10) "67c9ced91d"
// ["phone"]=> string(12) "415-392-0202"
// ["sessionToken"]=> string(32) "b13bd68240dfaedc80750241b9635e7b"
// ["updatedAt"]=> string(19) "2018-09-12 23:15:28"
// ["username"]=> string(11) "cooldude095"
// }
// 获取id为67c9ced91d用户的信息
$res = $bmobUser->get("67c9ced91d");
// object(stdClass)#2 (6) {
// ["createdAt"]=> string(19) "2018-09-12 23:15:28"
// ["email"]=> string(19) "bmobtest095@126.com"
// ["objectId"]=> string(10) "67c9ced91d"
// ["phone"]=> string(12) "415-392-0202"
// ["updatedAt"]=> string(19) "2018-09-12 23:15:28"
// ["username"]=> string(11) "cooldude095"
// }
// 获取所有用户的信息
$res = $bmobUser->get();
// object(stdClass)#3 (1) { ["results"]=> array(4) {
// [0]=> object(stdClass)#4 (6) { ["createdAt"]=> string(19) "2018-09-12 00:13:24" ["email"]=> string(16) "bmob2018@bmob.cn" ["objectId"]=> string(10) "da167d865e" ["phone"]=> string(11) "13711166567" ["updatedAt"]=> string(19) "2018-09-12 00:13:24" ["username"]=> string(8) "bmob2018" }
// [1]=> object(stdClass)#5 (6) { ["createdAt"]=> string(19) "2018-09-12 00:16:48" ["email"]=> string(19) "18897923095@163.com" ["objectId"]=> string(10) "dd62d2382f" ["phone"]=> string(11) "18897923095" ["updatedAt"]=> string(19) "2018-09-12 00:16:48" ["username"]=> string(5) "dq095" }
// [2]=> object(stdClass)#6 (6) { ["createdAt"]=> string(19) "2018-09-12 23:12:16" ["email"]=> string(19) "bmobtest111@126.com" ["objectId"]=> string(10) "47eed8d553" ["phone"]=> string(12) "415-392-0202" ["updatedAt"]=> string(19) "2018-09-12 23:12:16" ["username"]=> string(11) "cooldude117" }
// [3]=> object(stdClass)#7 (6) { ["createdAt"]=> string(19) "2018-09-12 23:15:28" ["email"]=> string(19) "bmobtest095@126.com" ["objectId"]=> string(10) "67c9ced91d" ["phone"]=> string(12) "415-392-0202" ["updatedAt"]=> string(19) "2018-09-12 23:15:28" ["username"]=> string(11) "cooldude095" } } }
// 更新67c9ced91d用户的信息 objectid sessionToken
// $res = $bmobUser->update("67c9ced91d", "b13bd68240dfaedc80750241b9635e7b", array("phone"=>"02011111"));
// BmobException: [206]: bmob.cn error: 无权限操作用户表,应用初始化时,请传入MasterKey%!(EXTRA string=)
// 请求重设密码,前提是用户将email与他们的账户关联起来
$res = $bmobUser->requestPasswordReset("18897923095@163.com");
// object(stdClass)#2 (1) {
// ["msg"]=> string(2) "ok"
// }
// 删除id为415b8fe99a的用户, 第一参数是用户id, 第二个参数为sessiontoken,在用户登录或注册后获取, 必填
$res = $bmobUser->delete("67c9ced91d", "b13bd68240dfaedc80750241b9635e7b");
// BmobException: [206]: bmob.cn error: 无权限操作用户表,应用初始化时,请传入MasterKey%!(EXTRA string=)
BmobObject 的例子 :: 数据库的增、删、改、查
$bmobObj = new BmobObject("dqBlog_content");
//添加对象
$res=$bmobObj->create(array("score"=>80,"playerName"=>"game"));
// object(stdClass)#3 (2) {
// ["createdAt"]=> string(19) "2018-09-12 23:36:05"
// ["objectId"]=> string(10) "b549848553"
// }
// 获取id为b549848553的对象
$res=$bmobObj->get("b549848553");
// object(stdClass)#3 (5) {
// ["createdAt"]=> string(19) "2018-09-12 23:36:05"
// ["objectId"]=> string(10) "b549848553"
// ["playerName"]=> string(4) "game"
// ["score"]=> int(80)
// ["updatedAt"]=> string(19) "2018-09-12 23:36:05"
// }
//获取所有对象
$res=$bmobObj->get();
// object(stdClass)#3 (1) { ["results"]=> array(2) {
// [0]=> object(stdClass)#4 (5) { ["createdAt"]=> string(19) "2018-09-12 23:36:05" ["objectId"]=> string(10) "b549848553" ["playerName"]=> string(4) "game" ["score"]=> int(80) ["updatedAt"]=> string(19) "2018-09-12 23:36:05" }
// [1]=> object(stdClass)#5 (5) { ["createdAt"]=> string(19) "2018-09-12 23:38:23" ["objectId"]=> string(10) "ddf4bf9946" ["playerName"]=> string(8) "KingGame" ["score"]=> int(88) ["updatedAt"]=> string(19) "2018-09-12 23:38:23" }
// } }
//更新对象b549848553, 任何您未指定的key都不会更改,所以您可以只更新对象数据的一个子集
$res=$bmobObj->update("b549848553", array("score"=>60,"playerName"=>"game"));
// object(stdClass)#3 (1) {
// ["updatedAt"]=> string(19) "2018-09-12 23:41:08"
// }
//删除对象ddf4bf9946
$res=$bmobObj->delete("ddf4bf9946");
// object(stdClass)#3 (1) {
// ["msg"]=> string(2) "ok"
// }
//对象的查询,这里是表示查找playerName为"game"的对象,只返回2个结果
$res=$bmobObj->get("",array('where={"playerName":"game"}','limit=2'));
// object(stdClass)#3 (1) { ["results"]=> array(2) {
// [0]=> object(stdClass)#4 (5) { ["createdAt"]=> string(19) "2018-09-12 23:36:05" ["objectId"]=> string(10) "b549848553" ["playerName"]=> string(4) "game" ["score"]=> int(60) ["updatedAt"]=> string(19) "2018-09-12 23:41:08" }
// [1]=> object(stdClass)#5 (5) { ["createdAt"]=> string(19) "2018-09-12 23:43:02" ["objectId"]=> string(10) "372a937457" ["playerName"]=> string(4) "game" ["score"]=> int(84) ["updatedAt"]=> string(19) "2018-09-12 23:43:02" } }
// }
//id为d345d271d2的field score数值减2
$res=$bmobObj->increment("d345d271d2","score",array(-2));
// object(stdClass)#3 (1) {
// ["updatedAt"]=> string(19) "2018-09-12 23:45:19"
// }
//id为d345d271d2的field score数值加2
$res=$bmobObj->increment("d345d271d2","score",array(2));
// object(stdClass)#3 (1) {
// ["updatedAt"]=> string(19) "2018-09-12 23:46:10"
// }
var_dump($res);
} catch (Exception $e) {
echo $e;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dq Blog</title>
<link rel="stylesheet" type="text/css" href="css/simditor.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/module.js"></script>
<script type="text/javascript" src="js/hotkeys.js"></script>
<script type="text/javascript" src="js/uploader.js"></script>
<script type="text/javascript" src="js/simditor.js"></script>
<link rel="shortcut icon" type="image/ico" href="images/shortcut_link.png"/>
</head>
<body>
<form method="post" action="index.php">
<textarea id="editor" name="content" placeholder="Balabala" autofocus></textarea>
<input type="submit" name="" value="提交">
</form>
<script type="text/javascript">
$(document).ready(function(){
var editor = new Simditor({
textarea: $('#editor')
//optional options
});
});
</script>
</body>
</html>