What is the best way to connect an iphone app to a mysql database? - iphone

I want the way with the fastest execution time. I'm not feeling comfortable of using web service because i need to create separate php pages and retrieve data as xml. If you think its good to use web service please tell me why. I want to code my database queries right on my c/objective c pages.
I've been searching for libraries. I saw this sequel pro - won't i have any problems on using this - like licensing issues? I also saw this libmysqlclient of cocoa but some say its not working well. I've also read about a library developed by Karl Kraft found here http://www.karlkraft.com/index.php/2010/06/02/mysql-and-objective-c/ but don't know if i could trust this.
I would really appreciate you help.

Definitely build a web service to act as an abstraction layer to your database. Here are some significant reasons in my opinion:
Since you want speed, you will be able to add caching when using the webservice, so you will essentially eliminate the need for identical queries to run (sometimes).
If you need to change your data model later, you just have to modify the webservice backend and don't have to update your app.
You can better control security by not exposing the database to the world, and keep it safe behind the web service.
Your database credentials should not be stored in an app. What if you needed to change those?
I strongly suggest a web service. Hope this helps.

Connect to your DB by PHP and output the result as JSON
is much better and faster then xml and less coding if use JSON Framework.
and never never try to connect to your DB from your iphone because it easy to sniff out the request from iphone.
Being safe then Sorry, keep that in mind

Related

How to Learn/Create a Database iPhone App?

I have a rather simple idea for an iPhone app. What I need to accomplish:
Allow login of users (which means I'll have to store usernames, passwords, and other account info).
Allow users to submit strings that other users can view.
Attributes attached to each string that must be tracked (i.e. "votes, views, comments, etc.).
As such, I assume I'll need to start learning about databases and working between a server and client. I've gotten my feet wet in OSX/iOS programming (specifically Objective-C) before. I want to learn how one can accomplish a data-based application and the needs I listed above.
I've done some light research and discovered something called SQLite (free and open-source is always good). Is this the right path to achieve what I want to do? I'm a total "noob" when it comes to this field of server/client/data "stuff".
Your help is greatly appreciated.
SQLLite is more like a local database. Really, the database that you will use is unimportant. It sounds like a project with webservices. Inside your webservices, you might connect to a Microsoft SQL Server or anything you want.
I think you should study how to setup a webservice that can be accessed in your code. Webservices is not an Objective-C topic, it applies to any platform. Your project is more like a web development project.
You can save user's credentials in keychain.
#Kinderchocolate is right about introducing database into your project.
It hears about a app which need transmitting data among clients.It means your need server database and local database.
For server database,I recommend you to use Parse.Parse is a platform which provide a convenient way to use their server database with Objective-c in your app.This tool will save many times and energy(it's not necessary to learn PHP,Apache,Mysql).Parse is not free of course,but it has a free period and enough for you to examine your idea.
Here's Parse!.
For local database,I recommend you to use Core Data,Which is provided by XCode.Core data is so strong to meet your need.You can find a way to use Core Data in many books.
Go try Firebase for database in the cloud. (On the server). In Swift 4 there is complete support for Firebase and SQLite

How to get data into Core-Data from an SQL Database?

I'm about to start an iOS project that requires pulling user's data from an SQL Database and viewing it within the App. Before I begin I'm looking for conformation that I'm taking the right (best) route.
My Plan:
App starts on login page (app will display data from another service)
App uses AFNetworking to post request to web service
Web service gets user data from SQL Database and sends back JSON
App uses JSONKit to parse the feed and load into Core-Data
App uses info from core-data to populate UI
Does this seem like an appropriate way to get the info into Core-Data from SQL? Any suggestions for doing things differently?
Thanks.
Are you receiving the response from the web server in JSON? If so, the fact that the server is using an SQL database is immaterial. What you need to know is how to parse JSON for inclusion in a core data store. Cocoa is my Girlfriend has a pretty good tutorial up.
Part 1
Part 2
To answer your comment, here's what I've done.
Display a login screen. The login credentials should be stored in the keychain for security. I've used SSKeychain for this.
To handle sending and receiving data from a web request your best option is to use a pre-built library. I've always used ASIHTTPRequest, but since it is no longer under active development, you should probably look around a bit before you commit to anything. I'm sure there are nicer and cleaner libraries out there.
You need to parse the JSON responses. I'm a fan of JSONKit. It's very fast, very easy to use, very robust.
Pulling data out of the core data store and displaying it in the interface will be no problem for you. If you create a new project in Xcode most of the setup will be done for you.
Now, there are a lot of projects out there that attempt to combine web requests, json parsing and core data loading into one framework. I've tried to use a few of these and haven't had much luck. The ones I've tried haven't been robust and very difficult to debug. Setting up your own request/parse/load code is not difficult at all, just a bit time consuming.
I am sure that there are a lot os ways to make implement this problem. Your solution is one of the popular solutions I guess but you could connect to the DB via a socket and talk with the database directly e.g. Going over a port 80 web site has the advantage that the possibility of some kind of firewall blocking the communication is very low. I would solve this kind of problem the same way I guess.

Advice on iPhone App needing to connect to remote MySQL

My App needs to connect to and grab data from a MySQL database sitting on a server. I've successfully interfaced with local SQLITE databases in my Apps, but this is the first time I've had to interface with a remote MySQL database.
I understand this process involves:
1) the iPhone App sending this request to the server
2) some sort of API gets executed and it does the actual "talking" to the Database on the server, and then it returns the query results as XML (or JSON.)
3) the iPhone then parses the returned information and uses it however it needs to.
What I need help with is step # 2 - the API. I don't know PHP, I don't know PERL - do I really have to learn one of these just to write an API? I thought that this iphone-to-remote-MySQL task would be so commonplace that such API's would already be out there, available freely - but I'm not really seeing anything.
I know Objective-C really well - but should I be using XML or JSON for this? Should I be learning PERL or PHP?
any tips or advice would be highly appreciated.
It's hard to give you a definite answer without knowing more precisely what you are looking at, but it sounds like your web service/API part should be quite light. In this case, it should be quite easy to write it in any language. If you know Objective-C well, it should be very easy to pick up some PHP or Ruby.
You mention PHP and Perl. The good thing I see with PHP is that it's available on any hosting service. For instance, with PHP you can make MySQL queries in a few lines of code.
Otherwise, if the web service lives on a machine that you own or if you have more flexibility, it might be easier to write something using Ruby and a small framework like Sinatra.
Regarding using XML or JSON to serialize the data, this will depend on what type of data your API returns. Generally, JSON will be much simpler and the support is good on both side:
- With Ruby, you can see how easy it is to use JSON here: http://flori.github.com/json/
- With Objective-C, you would use NSJSONSerialization available starting with iOS5.
Well you can talk to remote MySQL server using Objective C client directly from iphone
as show here

iOS webservice xml help

i am trying to create an app that connects to a mysql database, downloads the records in the table for the user then displays them in a UITableview which can be drilled down with the data that as downloaded from the mysql database. I would also like the data to be stored locally in something like sqlite. The data would then be modified then uploaded back to the mysql database.
My questions is where do i start? I have read alot of posts on google and they say that its best to connect to a xml which acts as a middle man between the database and the app. How can i create this xml file? is it something that is generated every time the app is launched or something done daily on the server?
If anyone can help me out. i know its a very broad question so if someone can point me in the right direction im not asking someone to right this app just a hand as im lost.
Thanks,
Aaron
I know others have mentioned links to libraries that let you connect to MySQL from iOS. I've not tried them myself but don't rule that out.
To answer your quest, you do not "create" the XML files. Web services are developed in a language, and written as applications. You would in essence need to write another application that runs on a server. That application would connect to your MySQL database. That application would also publish methods for getting at, and updating, data. By virtue of making your server a SOAP web service (in whatever platform), the data will be sent over the wire as XML.
If I have understood you want a kind of ORM?
If so you can check for Restkit and more specifically on the side of the object mapping system. It allows us to synchronize remote object/data locally with the coredata.
I have never used it, but I have seen a great tuto which talking about that here: Advanced RestKit Development (However I think it works only with json messages).
I hope it'll help you in your reflection.
I would recommend looking at XML Parser, Webservice, and Core Data tutorials.
SOAP and XML Response Parsing Samples for iPhone/iPad?
http://www.techotopia.com/index.php/An_iOS_4_iPhone_Core_Data_Tutorial_%28Xcode_4%29
That would be a good start, and I could give you some more material if you would like. As far as setting up your actual web service, I've never done that so I couldn't help you there.

Getting data from remote sql table on iphone

I am a beginner at both iPhone programming and SQL, yet I have basic knowledge of them.
I am planning to do an application that would plot a graph from data taken from a database of the server of my company. I know how to plot, I know how to extract data from an sql table, but what I don't know is how to access the server.
So do I have to go through some kind of oracle-like application ?
This may seem like a very stupid question because it might not even be possible but any answer will be appreciated.
Thanks !
Go through a web service for example a PHP page that returns JSON (or XML, but JSON is easier to parse).
I can highly recommend this tutorial
Once you have your web service, you can use NSURLRequest/NSURLConnection to download the data and use a JSON framework to parse it. Or, if you're using XML you can use NSXMLParser.
See this apple code for more info on downloading using NSURLConnection.
The best way for this will be, using APIs at server end that handle the client request and perform database interaction, so transfer of data among device and server, take place through XMLs that will be secure as well as fast.
It is definitely possible to contact a server (I can't imagine what would happen without that!). What you are looking for is NSURLConnection. Have a look at the example provided by Apple.