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.
Related
I've developed an android app that interact with my database by using some php scripts (one for each function of my app) that returns a json object with response data.
Now i need to build up a website too that do the same tasks of my app, but i would fix up my server code.
Should i have to maintain my app php scripts separate from website scripts (i'm planning to use some php framework to develop it), or there's a different way to do it?
No! Same script will work for all platforms.
If you follow proper protocols you will be good :)
Use Rest Console or similar tools to test your webservice on browser.
If you are able to get JSON response, then its good for all platform.
If you want to separate out the platforms and devices on server that can be handled by using user agent check at server end.
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 want to code an Android client and a Windows.exe server application (possibly PHP., I am still trying to decide).
I have no problem with developing the server app, but have not yet done any Android coding. Mostly, though, I am unsure about how to communicate between client and server.
A client aapp will login to the server then at regular intervals send its location (GPS coords) to the server which will store the data in a MySql database,
A second Android app will display a historical trail of where the first user has been using Google maps, plus a little more functionality.
Since I am not serving HTML, I am wondering whether to use HTTP GET / POST or a proprietary protocol over TCP/IP. I would like to encrypt it, so SSL seems in order,
Is there any compelling reason to use one or the other of use HTTP GET / POST or a proprietary protocol over TCP/IP?
Would coding my Android app be easier if I used JSON as my data format (or something else?), irrespective of the protocl used to transfer the data?
Hmmm, since much of the data returned as a response to GET by one of the apps will be data used to draw a Google map with a series of points showing travel, could I do the heavy duty processing on the server & return the HTML (or JS) necessary to display it an dhave the app embedd a browser in its UI to display the map? (the UI will also disply more, but maybe I shoudl just make it browser based HTML & JS, rather thn an actual Jav Android app? As you can see, I am confused)
[Update] I want to code both the clients and the server and to host the MySql database. I would prefer no 3rd party frameworks unless they are excedding simply to use and play very well together with Delphi or PHP.
I may recommend you to use Wcf with poco entity that provide you security as you want and create client in android to consume it.here is simple example of using wcf in android-http://fszlin.dymetis.com/post/2010/05/10/Comsuming-WCF-Services-With-Android.aspx
I would strongly recommend the use of the newest Google Play Services with the Google Cloud Messaging... It takes out of you all that work.
Check out, see if you like ;D
Google Cloud Message: http://developer.android.com/google/gcm/index.html
There is also a great video of this year's Google I/O about the maps improvement on Google Play Services:
https://developers.google.com/events/io/sessions/325172829
Are you trying to create App that can be delivered from Google Play Store or a Andriod enable Web application? You Question is confusing in your need. If you are looking to create Andriod Apps then definitely PHP is not going to serve it up. Look for Andriod SDK and create your interface using that, then for Windows Server EXE you can do PHP based API or as suggested by other answers. But for User interface PHP is no. You need to read and understand the different between APP and Web App. or your question is not very clear on topic.
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