I have created an android application using java, php(backend) and mysql(database)
. I have placed my backend php
code and the database on Linux
hosting server. My problem is that I can only read the data from the database, i.e., my application can fetch the data from the server, but it couldn t make any changes to the fetched data and also I get errors when I run using the server, but when I placed the database and code in local system it works perfectly on the localhost, but when placed in server it can only read the data but not insert, update or delete
the data. I have already given full privileges to the database in the server. Can anyone please help me regarding this aspect?
I think the server doesn t accept requests from outsider like mobile. So my question is
what do we need to do such that the server accepts requests from mobile side?
PS:我对服务器数据库给予了充分的特权,我还在海底清单中增加了因特网许可。
@Lie 瑞安 根据您的要求,我在此将服务器连接起来。
protected List<List<String>> callWebServer(String queryString, String statement){
List<List<String>> stringList = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("query", queryString));
nameValuePairs.add(new BasicNameValuePair("statement", statement));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(WEB_SERVICE_URL);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost,responseHandler);
JSONObject json = new JSONObject(responseBody);
if(statement.equals(DB_SELECT_STATEMENT) || statement.equals(DB_INSERT_STATEMENT)){
List<String> queryStrings = null;
// parsing query
if(statement.equals(DB_SELECT_STATEMENT)){
queryStrings = splitQuery(queryString);
JSONArray jArray = json.getJSONArray("output");
if(jArray.length() > 0)
stringList = new ArrayList<List<String>>();
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
String rowData = json_data.getString("rowData");
if(rowData.equals("nothing")){
// Toast.makeText(getBaseContext(), "No record found", Toast.LENGTH_LONG).show();
}else{
JSONObject getClassNameObject = new JSONObject(rowData);
List<String> tempStringList = new ArrayList<String>();
for(String valueStr:queryStrings){
if(valueStr.contains(".")) valueStr = valueStr.split("\.")[1];
tempStringList.add(getClassNameObject.getString(valueStr));
}
stringList.add(tempStringList);
}
}
}else{
JSONArray jArray = json.getJSONArray("output");
stringList = new ArrayList<List<String>>();
JSONObject json_data = jArray.getJSONObject(0);
stringList.add(getList("mn", json_data.getString("rowData")));
}
}
//Toast.makeText(getBaseContext(), "Event Added Successfully", Toast.LENGTH_LONG).show();
}catch(ArrayIndexOutOfBoundsException e){
}catch(Exception e){
Log.e("log_tag", "Error in http connection:"+e.toString());
}
而处理请求的《加拿大刑法》是:
<?php
include "connect.php";
if($_POST["statement"] == "select"){
$booleanRow = true;
// for select statements
$db_output = mysql_query($_POST["query"]));
while($row=mysql_fetch_array($db_output, MYSQL_ASSOC)){
$output[] = array( rowData =>$row);
$booleanRow = false;
}
if($booleanRow){
$row = "nothing";
$output[] = array( rowData =>$row);
}
print(json_encode(array( output =>$output)));
}else{
// for insert, update and delete
mysql_query($_POST["query"]);
$row = mysql_insert_id();
$output[] = array( rowData =>$row);
print(json_encode(array( output =>$output)));
}
mysql_close($link);
?>
预付款。