我正在使用PHP、mysql等传统技术构建它的项目,它是一个web应用程序。现在我们想在Andoid,iOS等平台上为移动用户开发一个应用程序。因此,我们正在考虑将MySql与Parse.com数据库连接起来。我知道解析使用NoSql类型的数据库来存储对象。
所以我的问题是,我们能把解析数据库连接到任何其他SQL数据库吗?如果是,那我们怎么能做到呢?
编辑
@Luca我刚刚创建了一个像你一样的新云功能。在下面。
Parse.Cloud.define("get_parse4j_object",
function(request,response){
// Parameters from client (iOS/Android app)
//var requestedObjectId = request.params.objectId;
// Calling beckend service for getting user information
Parse.Cloud.httpRequest({
method: "GET",
headers: {
'Content-Type': 'application/json'
},
url: "https://api.parse.com/1/parse4j/MLiOgxncUM", /* This could be your url for the proper php module */
//body: { "objectId":requestedObjectId }, /* Here you compose the body request for the http call, passing the php parameters and their values */
success: function(httpResponse) {
/* We expect that the php response is a Json string, using the header('application/json'), so: */
var jsonResponse = JSON.parse(httpResponse.text);
/* sample structure in jsonResponse: { "name":"Joe", "surname":"Banana", "birth_date":"01-02-1999" } */
/* Do any additional stuff you need... */
/* return the result to your iOS/Android client */
return response.success( { "myRequestedUserInfo" : jsonResponse } );
alert(jsonResponse);
},
error: function(httpResponse) {
return response.error({ "msg":"Unable to fetch this user", "code":123456 }); // sample error response
}
});
});我遵循卢卡·拉科解释我的方式。但是,当我从客户端JS调用函数时,会出现错误。这是我的客户JS
<script type="text/javascript">
Parse.initialize("APP_ID", "JAVASCRIPT_KEY");
Parse.Cloud.run('get_parse4j_object', {}, {
success: function(result) {
alert(result);
},
error: function(error) {
alert(JSON.stringify(error));
}
});
</script>在“网络”选项卡中我可以看到
POST https://api.parse.com/1/functions/get_parse4j_object 400 (Bad Request)而错误是:{“代码”:141,“消息”:“函数找不到”}我在哪里丢失并做错了?
发布于 2015-07-23 14:06:26
如果您的意思是像一个普通的mysql连接器,那么响应是否定的,您不能。目前,进行解析和其他相关操作的唯一方法是查询“从和解析”。要明确:
据我所知,您已经有了一个正常工作的web服务,因此您只需通过Parse将存储在mysql上的服务器上的资源代理到客户端。换句话说,您应该使用Parse (针对iOS或Android)为客户端上要检索的每种类型的信息创建一个Parse函数,并为您在设备上执行的每个操作创建另一个Parse函数,并且您希望保存在mysql上,始终通过分析系统。
我个人的观点是继续使用Mysql,特别是因为在Parse上,我们仍然对查询有很大的限制(没有组,没有不同,查询超时等等),而对于推送通知来说,这似乎是一个很好的服务。无论如何,所有这些都取决于软件的复杂性,正如我所说的,这只是我的观点。
编辑
这里有一个例子:
在分析云代码中,让我们创建一个名为'get_user_info'的云函数
Parse.Cloud.define("get_user_info",
function(request,response){
// Parameters from client (iOS/Android app)
var requestedUserId = request.params.user_id;
// Calling beckend service for getting user information
Parse.Cloud.httpRequest({
method: "POST",
url: "https://www.yourPhpWebsite.com/getUser.php", /* This could be your url for the proper php module */
body: { "php_param_user_id":requestedUserId }, /* Here you compose the body request for the http call, passing the php parameters and their values */
success: function(httpResponse) {
/* We expect that the php response is a Json string, using the header('application/json'), so: */
var jsonResponse = JSON.parse(httpResponse.text);
/* sample structure in jsonResponse: { "name":"Joe", "surname":"Banana", "birth_date":"01-02-1999" } */
/* Do any additional stuff you need... */
/* return the result to your iOS/Android client */
return response.success( { "myRequestedUserInfo" : jsonResponse } );
},
error: function(httpResponse) {
return response.error({ "msg":"Unable to fetch this user", "code":123456 }); // sample error response
}
});
});示例'getUser.php‘模块可以是
<?php
$expectedUserId = $_POST['php_param_user_id'];
// query your MySql db using passed user id
$query = "SELECT name,surname,birth_date FROM MyUserTable Where id = ".$expectedUserId;
// perform your query (the above one is just an example, would be better to use PDO and any other check, just to avoid SQL Injection)
// ...
// ..
// .
$resultQuery = row[0];
// sample json structure
$jsonResponseToParse = '{ "name":'.resultQuery["name"].', "surname":'.resultQuery["surname"].', "birth_date":'.resultQuery["birth_date"].' }';
header('application/json');
echo jsonResponseToParse;
exit();
?>希望它能帮上忙
https://stackoverflow.com/questions/31583013
复制相似问题