开发者

Seeking advice re: accessing MySql db via Android app

开发者 https://www.devze.com 2023-04-07 17:38 出处:网络
I\'m looking for some advice on the best approach to access a MySql db from an android app.I am trying to interface with a web site (not written by me) that uses PHP.I have access to the developer of

I'm looking for some advice on the best approach to access a MySql db from an android app. I am trying to interface with a web site (not written by me) that uses PHP. I have access to the developer of the web site, but, he does not know android. The web site is structured so that the content is dynamic (ie. news, notices, etc.) once you log on开发者_高级运维. At the moment, I've written code that can successfully log onto the web site. My next step is to obtain the data and display it on a mobile device. Here's my dilemma. I don't know if it is better to try and use an SQL API to access the data base directly, or, go through the existing PHP forms to access the data. Any and all advice would be greatly appreciated.


You should not connect directly to database from mobile devices for reasons stated here: Why is the paradigm of "Direct Database Connection" not welcomed by Android Platform?

Build a REST layer on you server, where you authenticate users and perform authorization and business logic.


I recommend the developer (or you) implement RESTful web services in PHP that provide you access to the data you need. JSON is a good data format that's easily processed in Android and easily generated in PHP (or RoR if you go that way).

On top of this RESTful layer, you should implement user-based authentication to ensure security and traceability of the api usage.

Here's a link to a couple REST libraries for PHP: https://stackoverflow.com/questions/238125/best-framework-for-php-and-creation-of-restful-based-web-services

And Android JSON parsing: http://developer.android.com/reference/org/json/package-summary.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号