How to connect android with mysql using PHP and JSON Part 2 (android php mysql json)

Опубликовано: 01 Ноябрь 2024
на канале: Computer Science lectures and tutorials
4,143
10

How to connect android with mysql using PHP and JSON Part 2 (android php mysql json)
hi, welcome to the second tutorial of how to connect mysql db from android using
php and json.
in this tutorial, we will see how to create php files.
we have to create 2 php files,
1 for insert
2 for select.
first we will create a php for insert.
then create variables for the server connectivity.

the next step is to create a connection.

now the connection is created, we will test whether the connection is success
our table contains 2 fields, uid and pwd.
we have to insert the values to these fields,
these two values is passed from android and received by php.
so use $_GET method.
now these values are captured. now build the sql insert query.
pass the variables inside the query
now the query is build.
now lets execute the query,
this mysqli_query returns the number of rows affected.
if there is 1 returned, then 1 row is inserted, so insertion is success.
if there is 0, no rows is inserted, so insertion is failure.
we will test using a simple if statement.
finally close the connection.
we created the insert php.
now lets create select php.
for the select query, many of the lines are same,
only few diff are there.
in this select php, we will take the uid and return the password.
so there will be only one get
modify the sql query. pass the uid into the sql query.
capture the result into a variable
now check if sql query is returing rows or not.
capture all rows. this will return an associative array.
an associative array stores values in the form of string as key.
store the result into a variable, now print the JSON values as output.
now if no result is found, return 0 rows.
close the connection
thanks for watching, in the next tutorial, I will show how to code in android
and get these values.
the link for the next video is in the description.
Video Link for part 1 tutorial - Creating users
   • How to connect android with mysql usi...  
Video Link for part 2 tutorial - creating PHP files
   • How to connect android with mysql usi...  
Video Link for part 3 tutorial - testing PHP files
   • How to connect android with mysql usi...  
Video Link for part 4 tutorial - Android code
   • How to connect android with mysql usi...