Get data from an online database

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Get data from an online database

Postby nah0y » Mon Feb 23, 2009 9:49 pm

Hi guys !

I have another problem :)

I need to save hiscores of my players online (in a database such as MySQL), but i really can't find a code or an example of how i could do this with android !

I just want to find something like :
Code: Select all
mysql_connect("sqladress", "username", "password");

and then use some command line such as :
Code: Select all
$answer = mysql_query("SELECT * FROM table");


How can i do this please ?!

Thank you !
nah0y
Developer
Developer
 
Posts: 30
Joined: Mon Jan 12, 2009 10:59 pm

Top

Postby Azalar » Mon Feb 23, 2009 10:14 pm

Use a web service to connect your Android up to a server side mysql database and interact with it that way.
Azalar
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Jan 13, 2009 6:09 pm

Postby nah0y » Mon Feb 23, 2009 11:17 pm

thx but which web service ?
nah0y
Developer
Developer
 
Posts: 30
Joined: Mon Jan 12, 2009 10:59 pm

Postby Azalar » Tue Feb 24, 2009 10:56 am

As far as I know there isn't any Android apis to support a direct connection to a MySQL database though if you learnt the protocol i'm sure you could talk to one via a raw socket connection, or there is sure to be a J2SE library you could adapt.
This is a bad idea and not mobile friendly as the data charges would be insane.
The idea I was proposing is this..
You would to have your 'own' server running MySql and have a web service on there that talks to your database and passes optimized data back to the mobile client.
You would need to write the web service too, as you already know Java you could use an application server like Tomcat for this.
Azalar
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Jan 13, 2009 6:09 pm

Postby nah0y » Tue Feb 24, 2009 11:07 am

Thx for the answer, so here my new question, because i want something "simple" to use and understand;

I perfectly know html/php and i can create an online form that ask "username" and then when i click on "Submit", i go on a php page that give me the rank of this person in my database (same thing to add people).

But is there a way to complete an online from throw an application, for example :
The player enter his username in a EditText, then clicking submit, i take his username in the :
<input type="text" name="pseudo" />

And then simulate a click on my html submit button, and finally grab the information on a result.php page ?
I already read the plusminus tutorial "Getting Data From The Web", so i would be able to get the result.php file but i really don't know how to complete a form via my application.

Thank you so much if someone finds out !
nah0y
Developer
Developer
 
Posts: 30
Joined: Mon Jan 12, 2009 10:59 pm

Postby Azalar » Tue Feb 24, 2009 1:27 pm

How about embedding the web browser component inside your android app and that way you could re-use the same form elements and web service?
The only thing you might want to change how you serve the data when its accessed via the mobile.
You can detect the user agent from the headers so you know whether the user is accessing this via PC or mobile
Azalar
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Jan 13, 2009 6:09 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests