I want to connect a MySql DB with my android application.
However, I DON'T want to/CAN'T use PHP for doing this.
Almost all solution for MySql connection with android on internet uses PHP.
I read somewhere that, If one don't want to use PHP then web service should be used.
But I'm not able to find any tutorial/sample example for the same.
Any help appreciated.
It seems you're mixing up some things.
A web service is simply some code on the internet (web) which allows you to receive and send information to a server, where it is saved per example in a database.
PHP is just a language, in which you can write a web service.
You can use a vast array of languages to create a web service ( read: expose your database) to other devices. Among others, you can easily do this in Java, .NET, Python ...
If you're looking for a way to connect to an external database without any web service / API in between, i'll have to disappoint you with the news that this is not supported by Android.
Most examples of a simple web service / a bunch of scripts contain PHP since this is probably the easiest and can be used on pretty much any server.
A webservice, is as it's called, a service, meaning that you have one side consuming it (the android client). if all you want is a persistent storage, you could use SQLite which is an SQL compliant solution which exists within android.
If it's possible to SSH to a server via Android, you could use that to connect to mysql, because the only other solution involves having mysql binaries installed locally on your android machine, and that's not possible AS FAR AS I KNOW, on Android.
One major reason for using a webservice (e.g. written in PHP) to connect to a remote DB is that you don't want to store the database login credentials inside your app. Because otherwise it'll be easy to extract your login for that database and access and edit it in a way you might not have planned (eg. delete stuff).
Its Possible to connect mysql database .
I have done with out using php file . I have used an spring configuration file to establish an connection to the database and dao to access the data from the database.
Create an Web Application that access the Server through the Spring Framework and an Servlet .
Create an Android Client Application tat make an get / post request to the Servlet , process the results in the servlet and return the response to the Android Client Application (json format ) Process the json format reponse in the Android Client Side and use it to your application
Related
I would like to write an Android App (with Android Studio) which uses a MySQL database.
What's the best way to implement it?
I have found on internet that I should write php files which send queries to the database. Then the php page return a JSON object which should be processed by the Android App (or something like that...).
Is this solution safe? Because I have to handle sensitive data like emails or GPS position.
Or else, are there other safe ways to let Android App connect to and retrieve information from the database?
You can call a web service which connects to your server, and a back-end program written in nodejs or PHP or Java or Python or any other programming language which has support (connectors/libraries) for MySQL database.
I have a website that uses MySQL database.
I'm trying to build an iOS app for it, so I wanted to use Swift to import information from the database and insert new information to it. I read that for the reading part I should use a PHP file to create a Json file, read that and extract the data. But I can't find the way to do it with swift.
Is there a way to connect iOS apps (written in Swift) to MySQL?
In the client-server architecture, the client is completely separate from the server, and they just exchange data thanks to a common "language" (in your case, certain fields encoded in JSON).
Your client is your iPhone app, written in Swift (but that's irrelevant).
You now need to build a server, which is entirely separate from the app. You don't need Swift for that. You will need a server (for example a cheap cloud VPS on Amazon EC2, Rackspace Cloud Servers, Microsoft Azure...) and you will have to create another application that runs on that server.
If it's just to pull data from a MySQL database, you can easily make that in PHP. Or you could use Node.js (which uses JavaScript: it's among the "trendiest" technologies at the moment), Ruby, Python, etc.For an example that uses PHP, you can check: https://stackoverflow.com/a/22367600/192024
To read the JSON data in your iOS app, then, you can use the builtin libraries: https://developer.apple.com/library/ios/DOCUMENTATION/Foundation/Reference/NSJSONSerialization_Class/index.html (it's available in Swift too)
I don't know what your app is doing, but if you want to ignore all the things with the backend (the server) you can always consider something like Parse Core and let somebody else take care of the backend.
I am an android newbie who is coming from PHP background. In PHP basically what happens is that
all of the database connections happen in php code(server side) and then it later coverts in html code(client side).
From what I have seen in android for database connection, we write a service in php using mysql. And from our Android java class, we make the service call(always aysnc I think), and then when the result comes, we update the UI(kinda like Ajax architecture and gwt).
The system above makes sense to me. I read somewhere that even though using JDBC is not practical on android, it can be still be used. Let' say for example's sake, we want to make the database call through JDBC. In a normal web app, I would put it in a servelet. But in android, we don't have that. All we have is UI widgets code.
So just to the understand the architecture, could someone please explain to me where I would make the JDBC call in the code? or in broader terms does it's architecture differ from traditional client/server side?
Like Php:
A brief recap of what you used to do in PHP is as follows:
Connects to MySQL server using PHP
Query the server using PHP function
MySQL server receives, parse the query and send the results back
PHP parses the response and then you displays (or do anything with) it
PHP has built in support for MySQL library.
Now in android we have built in support for SQLite. But the difference is SQLite stores its data on the device itself not on the server.
For database operations same procedure is followed using SQLite:
Using Android(Java) activity it connects to SQLite database
A query is sent to database
SQLite engine receives, parses the query and sends the results back
Android activity receives the result and then you can do whatever you want with it
But, Here comes the issue
This is only good if you want to store the data locally, like saving a users score.
Suppose, you want to have a leader-board in a game you built. Then you can't do it this way, because data is stored locally on all devices. For this we need to have all the users data stored on one/same place.
The Solution (like~in PHP)
We will save our data on an online server and will retrieve it whenever required. We can connect to any database engine on the server but MySQL is fast as compared to others. So, we will use MySQL as our database server and connect to it using a PHP web service.
That web service will do all (mostly CREATE and READ) database operations for you. This way you can save the data in the server and retrieve it globally whenever you want.
But, how it is done? Here are the steps:
Create a web service
A collection of PHP scripts which can read and write, to and from database
For security, plug in something like OAuth to perform transactions and encrypt data being transferred (Best will be to write this type of service in a framework)
Send READ or WRITE request from Android activity to web service
Web service receives, authorize, parse the request
Web service then sends the appropriate request to MySQL server
MySQL server receive, parse the query and send the results back to web service
Web service receive, parse the response and send the results back to Android activity
Android Activity receives the data and then you can play with it :)
You might have private databases in Android itself without using JSON etc. Just like you used in PHP with MySQL.
You might find lots of tutorials about SQLLite. But, here is official documentation of Google's Android page: http://developer.android.com/reference/android/database/sqlite/package-summary.html
The short answer is you can't use JDBC in android. The reason is JDBC is too heavy for mobile.
But you can use built in SqLite support to work with your local sqlite database. It has some limitations comparing to JDBC MySql driver but it should fit your needs.
Usage of SqLite is simple:
Connect to database
Send query
Get your data
Process data
The only thing you have to remember is that you should not use SqLite in main thread. You may create your own with Thread but the simplest solution is to use AsyncThread.
If you want to make calls to remote MySql database then your way is a bit more complicated
Write server side code that will handle requests from android and send it to database(e.g. using JSON)
Send request to remote server from your android device
Receive server's answer
Process it
As in above method with SqLite you should do it in a background thread to not to block UI.
-If needed you can use a local database (using SQLite)
-Server/client side in android are similar to any other application: you need a WebService handler which is usually (best practice) an AsyncTask.
Solution: nice and easy...
Create a .php that does the job for you, parse the result as a json workflow. Use your asynctask to get and parse the result. Add data to your database if needed. You can finally display a nice UI in the onPostExecute method.
I need to connect my mobile app to a database so it can send information from the app to the database.
I have looked at a ton of tutorials but they seem to irrelevant to my situation or write the entire application in XML. Can I connect it through script tags in the app or do I need to connect to via PHP and if I do where do I place that file in the application?
It is not clear to me if it is a local database on your phone or not.
If it is a local database on your phone I would use android's api.
If it is not, the best option is to write a SOAP or Rest service which need to run on a server. Personally I would go for a REST service, because it is less complicated. Although if there is sensitive data it might be better to use a SOAP service. You might take a look at this.
For calling your Rest services you could use a httpwebrequest. I belief this is an good example.
Write ur database related code in php and from your app send the post or get parametized url so it can be stored to ur phpmyadmin db
I have a mysql database with informations about users. Now I want to work with them in my iPhone app. Is there a way to bring the stuff from mysql to objective-c?
It's not an option to use the mysql c api because my web server just allows php.
Greekings, Valle.
Your question is not very clear but maybe this can help:
You can serve the information from your database with PHP (some XML or JSON can be useful) and then parse it on your iPhone App.
Or you can export your database and convert it to SQLite and use it directly on your iPhone.
With a bit more information maybe we can give you a better answer.
It sounds like you want to create an Application Programming Interface (API), in PHP on the web server that your Objective-C program will talk to using the devices internet connection.
Effectively you want to create special url's and request parameters your web server will use to pull database information, parse them into JSON or XML, and return them as plain text.
Inside your Objective-C application you will craft these URL's and parse the incoming JSON or XML into actionable data for your app.
Well, I don't think you explained your problem very well. Shared web hosting solutions usually don't offer access to MySQL servers from outside, it means you can access only from their servers (like PHP scripts on your hosting).
Solution to this is usually simple web service - REST, XML-RPC, SOAP.
Web service is some application that can be written in PHP and is running on your web hosting. This application returns data (usually in XML or JSON) via specific URL.
Example:
From your native iPhone you call
http://yourserver.com/webservice/?what=episode-list&tvshow=battlestar-galactica
and output will be XML with list of episodes.