php - How to check if mysql is connected to android on eclipse -


i trying fetch data mysql database , populate on listview.

i getting ip address of system this

string link_url = "192.168.19.6"; 

now in wamp server have file called

/product_api/getdataproduct.php"; 

i want file called in eclipse doing this

link_url = referensi.link+"/product_api/getdataproduct.php"; 

please right way of connecting android mysql , how know if file calling on eclipse connected mysql database.

this getdataoriduct.php file

<?php  include("koneksi.php");  $q = mysql_query('select * produk');      $v = '{"info" : [';     while($r=mysql_fetch_array($q))     {         $ob = array("<br>","<b>","</b>");         if(strlen($v)<12)         {             $v .= '{"id_produk" : "'.$r['id_produk'].'", "nama_produk" : "'.$r['nama_produk'].'", "harga" : "'.$r['harga'].'", "deskripsi" : "'.$r['deskripsi'].'", "stok" : "'.$r['stok'].'", "gambar" : "'.str_replace($ob,"",$r['gambar']).'"}';         }         else         {             $v .= ',{"id_produk" : "'.$r['id_produk'].'", "nama_produk" : "'.$r['nama_produk'].'", "harga" : "'.$r['harga'].'", "deskripsi" : "'.$r['deskripsi'].'", "stok" : "'.$r['stok'].'", "gambar" : "'.str_replace($ob,"",$r['gambar']).'"}';         }      }     $v .= ']}';     echo $v; ?> 

this included file

<?php     $conn = mysql_connect("localhost","root","");     $db = mysql_select_db("android_tokobaju"); ?> 

this error took place , method defined in oncreate method

jsonparser jparser = new jsonparser();         string nlink_url = link_url +"/product_api/getdataproduct.php";         jsonobject json = jparser.ambiljson(nlink_url); 

this stacktrace

java.lang.runtimeexception: unable start activity componentinfo{com.ecommysql.yonandroid/com.ecommysql.yonandroid.photoproduk}: java.lang.illegalstateexception: target host must not null, or set in parameters. 

this ambiljson function

public jsonobject ambiljson(string url) {          // making http request         try {             // defaulthttpclient             defaulthttpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost(url);              httpresponse httpresponse = httpclient.execute(httppost);             httpentity httpentity = httpresponse.getentity();             = httpentity.getcontent();                     } 

please above database connected mysql db. thanks

you in wrong direction friend. there lots of problem in code shared. have know before start.

why shouldn't use mysql_* functions in php

after json php

after code

include("koneksi.php");  $q = mysql_query('select * produk'); // change      $v['info'] = [];       while($r=mysql_fetch_array($q))     {         $ob = array("<br>","<b>","</b>");         $temp['id_produk'] = $r['id_produk'];         $temp['nama_produk'] = $r['nama_produk'];         $temp['harga'] = $r['harga'];         $temp['deskripsi'] = $r['deskripsi'];         $temp['stok'] = $r['stok'];         $temp['gambar'] = str_replace($ob,"",$r['gambar']);         $v['info'][] = $temp;     }      echo json_encode($v); ?> 

after on android side have use

simple parse json url on android , display in listview

you can't connect android mysql directly have use server side language fetch data mysql , feed android. in case php server side scripting language fetching data mysql , returning json response. android making http request server can json server , inflate list data.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -