Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send data from multiples tables (db.sqlite) to php
    text
    copied!<p>With this code I send information from my local sqlite database to my server(mysql) and it works fine. But I only send data from the table1. If I want to send the data of all my sqlite tables to my server how I can do that? </p> <pre><code>public class sendInformation { public SQLiteDatabase newDB; JSONObject jObject; JSONArray jArray = new JSONArray(); public void getValues() { try { newDB = SQLiteDatabase.openDatabase("/data/data/com..../databases/...db",null,SQLiteDatabase.CONFLICT_NONE); }catch(SQLException e) { Log.d("Error","Error while Opening Database"); e.printStackTrace(); } try { Cursor c = newDB.rawQuery("Select * from table1",null); if (c.getCount()==0) { c.close(); Log.d("","no items on the table"); }else { c.moveToFirst(); while(c.moveToNext()) { jObject = new JSONObject(); jObject.put("ID", c.getString(c.getColumnIndex("ID"))); jObject.put("Notes", c.getString(c.getColumnIndex("Notes"))); jObject.put("Cellphone", c.getString(c.getColumnIndex("Cellphone"))); jObject.put("Date", "null"); jObject.put("Address", "null"); jArray.put(jObject); } c.close(); Log.d("","ALL the data in the DB"+jArray.toString()); int arrayLength=jArray.length(); Log.d("","Lenght of the jArray"+arrayLength); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,9000); HttpConnectionParams.setSoTimeout(httpParams, 9000); HttpClient client = new DefaultHttpClient(httpParams); String url = "http://ipaddress/..../test.php?arrayLength="+arrayLength; HttpPost request = new HttpPost(url); request.setEntity(new ByteArrayEntity(jArray.toString().getBytes("UTF8"))); request.setHeader("json", jArray.toString()); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need if (entity != null) { InputStream instream = entity.getContent(); String result = RestClient.convertStreamToString(instream); Log.i("Read from server", result); } } } catch (UnsupportedEncodingException uee) { Log.d("Exceptions", "UnsupportedEncodingException"); uee.printStackTrace(); }catch (Throwable t) { Log.d("","request fail"+t.toString()); } this.newDB.close(); } } </code></pre> <p>As you can see, I get all the data from <code>table1</code> and I create a jsonObject. </p> <ul> <li>I pass that to the test.php file, but if I make another query from table2,table3..., I have to put the values of the second and third table in the same JsonObject? </li> <li>If I do that, how will I know which data is from which table? </li> <li>If I can send multiples jsonobject, how do I do that and how will I receive that data in my test.php file. </li> </ul> <p>Right now I do it with <code>$json = file_get_contents('php://input');</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload