How to get data from MySQL database to Android app Unknown الأحد، 12 أبريل 2015 label android label java label php Java private static class Product { private String name = "" ; private String price; private String quantity; public Product( String name, String price, String quantity ) { this.name = name ; this.price = price ; this.quantity = quantity ; } public static ArrayList products; /** * Generate products. */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi") public static void generateProducts(){ String result = ""; InputStream isr = null; products=new ArrayList(); try{ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/getdata.php"); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); isr = entity.getContent(); } catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(isr, "utf-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } isr.close(); result=sb.toString(); } catch(Exception e){ Log.e("log_tag", "Error converting result "+e.toString()); } //parse json data try { JSONArray jArray = new JSONArray(result); for(int i=0; iPHPconnexion.php "; echo $e->getMessage(); die(); } ?> getdata.php name=$n; $this->price=$p; $this->quantity=$q; } public static function liste() { global $cnx; $sql="select * from products"; $res=$cnx->query($sql); return($res->fetchAll(PDO::FETCH_OBJ)); } //**************************************************** } $liste=prod::liste(); print(json_encode($liste)); ?>How to send data to mysql from android app Share This : Unknown chevron_left chevron_right
comment 0 التعليقات:
more_vertsentiment_satisfied Emoticon