RUVIDEO
Поделитесь видео 🙏

How to connect android with mysql using PHP and JSON Part 4 android php mysql json

How to connect android with mysql using PHP and JSON Part 4 android php mysql json

hi, welcome to our last part of this tutorial on how to connect mysql db to android
by using php and json.
in this part, we will design the android app.
we are going to implement a db access from remote server. this is a large task
and cannot be done in main thread.
so we have to do in separate thread.
before we do this, we have to add internet permission to our app.
now create a new thread for read(select.php) and a new thread for write(insert.php)

the asynctask has 3 methods
1)onpreexecute -executes before thread (all initlizing )
2)doInBackground -main execution (main db access)
3)onPostExecute - after execution (after thread execution, result publishing)

The process of accessing remote server is simple.
1) create a httpclient
Create a Httpclient instance.
2) create a httppost
the post is the filename we want to access. the filename is
http://www.microfusionsmartsolutions.com/phpfiles/select.php
http://www.microfusionsmartsolutions.com/phpfiles/insert.php
if you are using a wamp server then the filename should be
http://10.0.0.2/phpfiles/select.php
http://10.0.0.2/phpfiles/insert.php

after creating the post, we have to pass values to the file
the select.php takes uid and gives pwd. so uid should be passed.
to pass a value we have to use arraylist with namevaluepair,
now add the uid to namevaluepair
the namevaluepair is in the form of (key,value)
key should match the $_POST in the php file, the key is uid
now we have created a pair, then we have to add the pair to the post.
the post is ready.

3) execute the post and get result
to execute it use execute method in httpclient. and recive a response.
the post is executed and the result is recieved by the client.

4) convert result to inputstream
we have to convert the result into inputstream so that we can parse it.


5) build a string from inputstream
we can now convert the inputstream into a string.
convert the bufferedreader to string we will read one line at a time.
if there is a newline, then we will insert a line break.
close the inputstream
now we converted the inputstream into a string.
JSONObjects will return the key,value
where key is the name of the attribute in table
the key is Pwd
if we want to process JSONArray then the steps is


6) check for JSONArray or JSONObject
there are 2 types of results in string, one is JSONArray and other is JSONObject.
when the result is single, the the result is in form of JSONObject.

when the result is multiple, then the result is in the form of JSONArray.

in our case (select.php) it takes uid and returns a single password.
so the result is single.
so the result is in form of JSONObject,

in many cases the result will be multiple, for example if we want to find the
list of users, then the result will be in form of JSONArray, because the result
has more than one JSONObject.

we first find how to process JSONObject.
simple, convert jsonobject from json array by using a for loop
process each jsonobject.

there is another chance, JSON values will not always return from the server
if you look at the php file , we will notice one thing
a string value(not a json value) will be returned when there is no rows
so we must try to handle this situation.
7) decode JSONObject
8) publish result
now it is time to publish the result to our main thread.
do in onPostExecute

we will test the module, the select part is working.
now lets do the insert part.
the insert part is very simple. just copy all the select part
and remove the unwanted items.
First we will copy the code
change the filename from select.php to insert.php.
the insert.php gets 2 values uid and pwd.
there is no need for JSON processing.
done, we will now test
I forgot to add handler.

it works, thanks for watching. Kindly support us by subscribing the channel.

Video Link for part 1 tutorial - Creating users
https://www.youtube.com/watch?v=NOZvVUXYlz4
Video Link for part 2 tutorial - creating PHP files
https://www.youtube.com/watch?v=guPFS1PGeaw
Video Link for part 3 tutorial - testing PHP files
https://www.youtube.com/watch?v=kKTvsZWJ5qc
Video Link for part 4 tutorial - Android code
https://www.youtube.com/watch?v=OBssydUh-pE

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «How to connect android with mysql using PHP and JSON Part 4 android php mysql json», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.