Skip to main content
GameDev.net gamedev.net
🔒 Locked

how to run a php code with your android app

Started by moeen k Sep 5, 2014 at 12:19 PM 4 replies 13.3k views
Original Post
moeen k
moeen k

hello my friends. im working on a project that needs to work with mysql database and query it from an android device. how can i really dot that? most of tutorials is saw in internet make it with php files. but i didnt understand it very well. should i make my php files seperatly for each query and put it on host and call it by pressing button from android? can you explain it to me?

thank you for helping me

HyperV
HyperV

HI

not very sure what you mean but if you want to make a webbased app for android PhoneGap is something you should look at.

PHP is more serverside.creating buttons(CSS) and functionality they use Javascript.

Link to PhoneGap http://phonegap.com/

HyperV

moeen k
moeen k

thank you hyperv but i meant something else

DiegoSLTS
DiegoSLTS

You need to be clear with your question, the title and what you ask later are different things.

Responding to your title, you can't run php code directly from Android. PHP runs in a server, the idea is that you create a web service (in PHP or any other language) and from your android app you do HTTP requests (a URL plus some data) to that web service. Those requests are interpreted by the server and the php code related to that url is executed with the data you suplied in the request. When that code finishes, the server sends the response to the android app with the output of the php code executed.

Now, for the first post, you could create a connection directly to the database, but it's easier and much more common to add the web service in the middle. The advantages of using a web services are more control and security.

If you setup your database to be accessed directly from anywhere, even with username and password, someone could get that information and do ANYTHING (drop tables, change data of every table, etc). WIth the web service you only expose what you want to do. If the android app is only supposed to query information, then your web service will grant access only to select queries.

Most examples use PHP since it's a language mainly used for web services and it doesn't need a powerfull server. So, do a little research on how to use PHP to access a database and do the requests, it may be harder to learn all this at once, but it's the right way to do it and it's really usefull since most apps today do some kind of request to a server. Keep in mind you'll be doing 2 really different things, the web service (code that will run in the server, query the database and return the information to the client) and the client (which will request the web service and display the information), it's not just the app.

Jo D.
Jo D.

If you are making Java app i dont think its very smart to query directly from your app. Depends on app type ofc but maybe some type of SOAP would help you to achieve your goals. Hard to determine what you are trying to do. Web based app, java app or what?

moeen k
moeen k




what you are trying to do. Web based app, java app or what?

my friends please!!!!

it was a mobile programing competition and the challenge we chose to do was to make a database that every could see that. so it had to be online. so we had to choose mysql instead of sqlite.

it was a health system that your doctor takes your information and give feedback to you and every one with a certain pasword can see your info like your family. just that. sorry for asking that here.i am a game developer and i thought people here answer better than stackoverflow.

in the end our program didnt work very well :|

i think now you know what i meant

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.