Query data in a table in a database of a host service using Retrofit (Android)

1

I am looking for a way to consult data in a table of a BBDD hosted in a host service by retrofit from android Studio.

The problem is that to enter and view the data directly with phpMyAdmin from the host service I need:

    1. Put my user and pass for the host service.     2. Select a BBDD. 3. Put my username and pass for phpMyAdmin.     4. And select the table from the database.

I know that once the object of the Retrofit class is instantiated, I have to give it a basic URL. Because I guess I should put some more credentials, but I can not find an example of how to do it.

    
asked by Las Perseidas 13.01.2018 в 04:22
source

1 answer

0

Retrofit allows you to connect your Android app with an HTTP API, but NOT directly with a MySQL database. The most normal thing in this kind of situations would be to develop a REST API on your server, (as you mentioned that you used PHPMyAdmin, you can probably do an API in PHP) so that through HTTP calls (which Retrofit can do) allows you to access the data hosted in your MySQL.

As an alternative, you could look for a library that allows you to connect Android directly to a MySQL server, but it is not a recommended practice.

Edit: I was finding out a little more, and someone already did the dirty work. You can look this library: by adding a php file on your server, it allows you to directly access the data using a json data structure. If you still think about connecting directly to MySQL, you can get some ideas from this post , where they try to access MySQL directly from Android using a jdbc driver.

    
answered by 13.01.2018 / 14:27
source