Android – PHP – MySQL Scheme

Android Mysql PHP connect

  • connect android device to PHP Script
  • PHP Script will fetch data from the database. It will encode it into json format and send it to the device.
  • Android App will get these encoded data, then parse the data and display it on android device.

The PHP code will be very simple:
– Connect to the database
Run an SQL query, with a WHERE block depending on data from POST/GET values
– Output it in JSON format, the square bracket [ represents starting of an JSONArray node whereas curly bracket { represents JSONObject node.

food.php:

<?php
mysql_connect("127.0.0.1","root","12345");
mysql_select_db("FOOD");
$sql=mysql_query("select * from FOOD where FOOD_NAME like 'A%'");
while($row=mysql_fetch_assoc($sql)) $output[]=$row;
print(json_encode($output));
mysql_close();
?>

Android application:
– Use a HttpPost to get the data,
– Convert response to string
– Parse JSON data, and use it as you want

user unique id – I am generating unique user id in php using uniqid(”, true) function. Sample user id will be like 4f074eca601fb8.88015924

Encrypted Password – This password is stored using base64_encode method. Each password will need two columns to store in database. One is to store encrypted passwordand second column is to store salt used to encrypt the password.

Retrieve Data From a MySQL Database

mysql_fetch_array()which fetch a result row as an associative array, a numeric array, or both.

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 

via 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: