Femn Dharamshi
Femn Dharamshi

Reputation: 577

PHP API for android using mysql

So, currently i am using firebase for storing my app data online, I would like to create my own database, so i was planning to get a 100gb bandwidth hosting plan with php and mysql (is that bandwidth enought) per download, my app downloads approximately 0.4MB of data (as per firebase).

So, to create the api, i just have to encode the mysql data into json and print it ? then my android app will read it and use it ? is this the best method ?

$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
    $rows[] = $r;
}
print json_encode($rows);

or is there any other, more efficient method to do this ?

Upvotes: 1

Views: 86

Answers (1)

Ajit Maurya
Ajit Maurya

Reputation: 56

Yes but you should send response code like 200,403 as well. here is a similar question

How to write a REST API?

Upvotes: 1

Related Questions