How to connect android application to MySQL Database in XAMP Server

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to my android tutorials in this tutorial I'm going to show you how can we connect our Android application to MySQL database using PHP first we need to create a MySQL project I'm going to create a MySQL test next next next and finish ok first name first thing we need to create a database in my PHP admin my PHP admin is M installed in them I have installed Sam server or you can use vamp server or any me my database is test create and my table name is user and it have two columns and there is user name there will be username and password and first one is username and it has type watch or a second one is password it has watch or data type watch or 50 and 50 in both are the part of a primary key okay in Google Wave SQL yes it is great creatable test this is my database name user this is my table name user this is my column name watch all 50 not null password and this is my constraint that is primary key which is called combined prime B K okay close in hit save and my table is created successfully so now I'm going to insert our data and this my database so first one is using in its tests and password is test hit go and 100 is inserted successfully into my user table with username password test test next thing we need to add a user add new user which have the same name as in the table so test password will be test test and edit its privilege database for user account not data set and select and only give its disusing in the permission of selecting the data from the database of test hit go and one user created or edit successfully this is my user and test yes yes okay now we have successfully set up our database with the one table user which have username and password let's go to are they out change this to relativelayout what is this okay change this one to relativelayout relativelayout change told me this we have made this edit text and match parents wrap content and text size in 25 SP for describing your phone size use SP units so text I have username tests I'm using manually if you want to on in the running of the application you can remove this line in droid and enter text okay next we need its ID ID is username in it is good to go copy paste and ID will be password no password will be test and it have input type as text password or you can specify email for your email confirmation or any anything like this okay we have created our to edit text or one more thing we need a button button and button is the mass parent grab content and it it should have its text size is 25 SP and its text is login and its own click even will be log in BTN login BTN and create login written even handler in this main activity log in BTN me donate its ID they see how our okay we have to specify your location but within cues instead of we can use our layout that is called linear layout match parent match parent and in grab all these text in the edit text and button in this linear layout linear layout we have to specify its orientation rotation will be vertical so let's see yes ok it's time to add some padding and margin layout margin will be NDP and padding will be MVP we are good to go okay one more thing we have to align this layout in center of the parent truth and you can feel the difference okay okay okay one more thing change it to the app content and you can feel the difference yes we have successfully created our layout it's time to get their ideas in the code section and edit text password a user password user and last one is the user is equal to and it takes five / ID r dot ID dot user name and password is equal to' and it text when view bhai D or thought ID dot password and in the login button we have to get their text so a user is equal to user dot Inc it takes toward two string actually get this clear - so return string so it is better to be converted to convert the values into string get this to string it is a good habit to convert okay we have successfully created our lay out our website know it's time to create some PHP api's go to your zem folder vamps order folder we I have installed them so I in Sam in the htdocs folder which is the root folder of your localhost or your IP create a new text document login dot PHP okay note that plus plus is in your editor which give you the abilities to which give you way to edit your coding your files in code view this very good and name is Jordi be my DB name is AZ test and name is your username username and my user name is will be will be come from my application front-end so same as for password post and password and one more thing we need our host and host is equal to which is localhost or you can also get this form your front-end okay next we have to get the connection declare a variable within corneum the string method string variable string symbol with some type of names it's define variable in PHP coding so MySQL I connect this is the method to get the connection first we have to specify the host then we have to specify the username user then we have to specify the password and last one we have to specify all be be if if somehow our connection is connected successfully that mean it's not null it do some coding else if return nuts it's eco a message is a display in message in eco is standing phone system dot out dot print line source it displaying from message output echo not connected none no once our connection is connected successfully we need to we need to now you get some result or Curie QV r QE will be select static form user vir user like user and password is like password here we go and now we have to execute this cutie and get some result and store the result in a variable name with wizard MySQL I Curie and first MySQL link link will a link which is our connection and our Curie and Curie is stolen cue and now we have to check if this cutie result some dessert returns some rose we have to check that forth and we have to my SQL blows counter of one my number of rows number rows number rows and that is decided variable if these are greater than 0 which means we have some result in returned by mice calculate that means we have login successfully so echo login successful otherwise we have we don't have a user with the specified user name and password in the table somehow if the username exists in the so called database user table eco login field okay I think every is everything is all everything is done so let's move to this create a new Clause named new Clause with the name of background background okay and it will in extent extends async task a same task and wait wait wait don't confuse your boy with the void with capital and small void use your small capital words in this let's implement some of method okay we have to string result is equal to this decider okay it's a some matter because if it's certain time didn't match with the method that is returning and we're showing some error shrink okay we are good to go and we have to specify we have to change this into string string and it shrunk again another changes to this video by you to strain and we are going to go go to your main activity tour Java and create a background oops I entered I have entered our refactor over in rename file refactor rename background okay no it's time to create an object of this new gold and preaching taught as this is a implement extend from the class of NC async task so it will get the execute method and we have to specify the user and password and its parameters no get username and password here shrink in user is equal to words and enter zero position and string password is equal to enter words enter first position okay let's create a string connection string is equal to s typically in localhost and don't forget to specify your port number in case of if you have installed Sam server at a stove Ottumwa okay next we have to get the URL you oil gets equal to new URL and specify your connection string in it o is showing probably shown some yes exception result is equal to get message okay next we need to open the connection on the specify the URL so for opening question we have two HTTP URL connection is equal to zero dot upon connection what is this if TPP is the object name okay and the catch clause and again result is equal to get message no was the problem with this line oh I think type costing so type cause the connection into HTTP URL connection and we are done and the request matter which will be paused and HTTP dot set input doe input and set it up to draw and send to output and set it to true okay we have configured our ACP connection and we have opened this connection time to get the reader writer so first we need our output stream input stream is equal to new HTTP dot get output stream and no buffer writer writer is equal to buffer writer and new on we need to get the writer on the output stream so new output stream writer and four PS and define its encoding encoding will be utf-8 this is the encoding scheme for the writer next we need are some we need some data or which we want to write to writer on the output stream and output stream bill passed at right tail and past head writer data to HTTP connection so we need a data source string data is you are l encoder dots in code and what we want to encode we want to in cold I want to encode the first user templates using scheme its encoding scheme encoding scheme will be utf-8 introduced eight oops and equal to equal to what able to word is you're on an encoder dot in code in coal and we want to encode our each user variables so user dot CMS encoding UT f dot in utf-8 in then we need and operator and we have to copy this and write this line of code same as for password make sure the variable name or the name of these strings are same as the name in the post method got it okay next we have we are ready to post we are ready to guide this data right and what we want to write we want to write this data string and we have successfully raipur dot flesch then I write dot cause and then output stream dot kills we are successfully send the data to H PHP API is now we have to get some result from this send data so for that we have to input stream htpb dogs kids input stream okay and buffer reader we need a buffer a turbo four-litre will be a leader and new output input stream reader and same as input stream pass the input string variable and the encoding scheme for this encoding scheme we have different that is is for double eight five nine if you don't know the encoding scheme you have to check out the encoding scheme PAP official Android studio documentation so long oh no we have to get this result string line is equal to this and wide while are the line is equal to reader dogs read line is not equal to null result is equal to line okay now we have to read a dot also input stream table clause in HT PP dot let's connect ain't last one result return deserve it okay in case of any exception even return a message in the result and result okay we have to show this result in some kind of messages in today's message box or on pre execute on post execute or import this generate this override override methods okay we need a alert dialog and our dialog on pre execute we have to time is equal to mu alert I am dot builder builder and contact context dot no dialogue builder not too eh we need a Content also we have context context and we need a context on activity we want to display this color dialog box so we need to get public background context context this dot text is equal to context and dialogue and next we need you need to dialogue dot set title and title is login status on post is it yours we have to show some messages who died on bot message and message will be s dialogue dot show okay we have successfully created our we have successfully created our application let's try oh we have to upgrade our manifest that is at work we have to and a user permission which is internal permission so once is done with the loading we are good to go let's revise what we have done till now we have we have create oh we need a context here which is this and Android application first we create our website first first we have we had create we had created our database with the name of test and it has a user table which have two columns which is username and password then we insert a data into it at this table user table which is username and password and get is test and test then we design a layout then we design a layout and layout have three values username password and login button and then we create a new cloth new class there is background and which is extend is in task in in basic su task we have create three methods and there is basic you'll post execute in doing background pre execute method run and the starting of the process post execute method run when the results are returned finished and doing background wife the application and why the process is in running state and we have created unlocking PHP file which they have four variables DP username password host and username and password will be come from application interface and there is username and password then we get a connection on dead username and password which is come form application front-end as MySQL I connect and then we said in check if connection is true it's mean it's not empty then we select then ship some data from user tables which have user like every name in the field of the application and then we check the if the result I get a sum zero it's mean we have successfully log n if not log-in fail or if connection is returned null which means user is unable to connect with the dis host this user with this username and password with this database so then we will get not connected okay let's hit the Run button in [Music] if you are running this application on into I'm running this application on SDK version between 21 and 26 is v if if you want to run this application between any Hall in this lower level you you can change mini main it's still a virgin to 19 which is minimum till no the development of the Android SDK come on okay okay one process is running left I'm sorry my computer is taking too much long time to run this application for this tutorial I am simply shown you how can we connect to our MySQL database in the next tutorials I'm going to show you how can we insert data into MySQL database and how can we retrieve some data and show this data into Android application using PHP PHP API is okay it is installing my appeal apk into my Android emulator and here we go the test button invalid host login.php oh okay it's chained this error because because this not in this emulator not connected to local host I am posting my videos and changing providing my IP address to the connection strength Oh welcome back guys I have a replace local host in this connection string with my current IP of my internet I'm sorry I can show you my IP address for where so that's why I didn't record that editing part of this so okay let's hit run login and undefined variable DB in line number seven warning MySQL num rows scripted parameters 1 to be MySQL this solid boolean given okay logging fail you can see log-in failed let's see why this is coming and [Music] this in line number 7 DB DB the oops here should be D be okay keep safe and again come to your Android application and you log in button and it's showing our warning my astray number or suspected parameter want to be my SQL dessert MySQL I result boolean given in log in on line number 12 login field okay login Phegley to mysql password and this is my connection now let's see it is shown or we are unable to connect our database or not it's okay hit this one and hit login syntax error expected else expecting end of the file nineteen oh I'm sorry guys no his button login you can see I don't have to change coding I only have to change I only have to change these bacons programming warning maestria number is respected I will be back short guys when I remove this error warning welcome guys I have a very stupid error days f R and from instead of pugs right phone and hit C inch let's check I mean login and I hope we will login connected login successful yes we can login with this code and mainly see if let's check our application is working perfectly on Nord if I specify username test test which is exist my user table in my database here we go you can see I only have username test and test in this database but in privilege in my user I have my user that is frizzy and other one over and I'm going to give in another eye username my juicer which is already exist in my database so listen okay here we go guys I have give my user name fizzy and my password for this particular user in this my user table of which is my actually root user to access all of these there are ways you who can access all of the data in this database one I hit login it will show login fail because this username and password didn't exist in my this user table I hope guides you understand the way of coding the way of describing the method how can we connect our Android application with the PHP MySQL using PHP and thank you for watching guys and please do subscribe and like my videos like my channel and thank for your sport
Info
Channel: Alifio Tutorials
Views: 188,022
Rating: undefined out of 5
Keywords: MySql Server, XAMP Server, Android Studio, connect android application to XAMP, PHP coding, PHP programming, writing PHP api, android application, how to connect, creating database, in MySql, Login module, Login Application, Insert Data, Update Data, Delete Data, MyPHP Admin Pannel, With out Errors, Successfully, Simple Steps, easy Steps, Background Class, using AsyncTask, java programming, MySql Database Connection, MySql Database
Id: 4e8be8xseqE
Channel Id: undefined
Length: 43min 14sec (2594 seconds)
Published: Sun Feb 11 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.