I would like to fetch data from a phpMyAdmin server. The only function I know, is this :
private String getPage() {
String str = "***";
try
{
HttpClient hc = new DefaultHttpClient();
HttpPost post = new HttpPost("http://mywebsite.me");
HttpResponse rp = hc.execute(post);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
str = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
e.printStackTrace();
}
return str;
}
It doesn’t work because I need to authenticate myself with an username and password. Another reason that I think this function will not work is that it grabs the source of the page (ctrl+u in Chrome) and the values that I need aren’t there, they are in a table on the server. How could I do that?
You’re going about it the wrong way I think. I presume that
phpAdminis actually phpmyadmin, and you are looking for data from your database?PHPMyAdminis a selection of pages that does what you want to do for a browser: extract information from a database. You don’t need to go trough that page to get the info. You can either write some .php files that extract the data for you (for instance in XML or JSON) and fetch them with above code, or try to contact you database directly, without intervention of the apache server.Edit: it looks like contacting directly isn’t too easy, and you’r login should be valid for external connects (which it might not be). I guess you should write a so-called “REST” interface (a bunch of files that does basically what phpmyadmin does, but not as complicated: you request a table and it gives you this without all the other stuff phpmyadmin shows).
look for instance here for more information on how to do that: http://www.helloandroid.com/tutorials/connecting-mysql-database