Tutorial to Connect iPhone app with MySQL database? (Interface Objective-C with mysql) - iphone

I am looking for a tutorial on how to make an iPhone app that fetches data from and writes data to a MySQL database. I've seen some other threads saying that I should make an abstraction layer so as not to connect directly to the database from my app, but I'm not sure of how to actually go about doing this. Does anyone know of any tutorials that involve creating an abstraction layer for a MySQL database or connecting a MySQL database to an iPhone app?
To clarify, I am looking for a secure method that wouldn't allow people to sniff out my MySQL host, username and password. It seems like the libraries that connect directly to MySQL from the iPhone all have this problem, but please correct me if I'm wrong.

This is a really good tutorial that covers how to communicate with MySQL from an iPhone app using PHP:
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app

I know only one library, which makes possible connection from iPhone to MySQL. This is port of official MySQL C libraries created by Karl Kraft.
Author published also small portion of samples, which describes how to use this library.
UPDATE (Karl Kraft's broken link)
Instead of link above, I used an archived copy.

not up to date, but this tutorial helped me a lot:
http://codewithchris.com/iphone-app-connect-to-mysql-database/#connectiphonetomysql

Here http://blog.iosplace.com/?p=30 is a snippet that uses the original mysql client lib, and here http://www.karlkraft.com/index.php/2012/01/ is a link to a 3rd-party connector.

Here is a nice tutorial on how to connect to a database using web service layer.
From a practical perspective you could connect directly to a database from an iphone because that is a client server transaction. The problem is that you would need to expose your database server an issue that many would find very disturbing, because you would expose your server which hold your most valuable resource "your data". Of course you can implement and could be a good solution for rather small projects. But you would need to implement the layer which it would be used to connect on the iOS app, adding more complex to the matter.
Using a web service is more reliable even from the iOS developer, because there is a very extensive api for using web service, which offer great functionality (asynchronous transactions, threads management,JSON Mapping, XML Mapping) to name a few.

Use the library OHMySQL. It copes with MySQL through MySQL C API.

Related

How to connect to MongoDB in an iPhone App?

now I have an iPhone App and basically I want to exchange data from my database (MongoDB) on a server.
Could you please tell me exactly what I should do?
Forgive my innocence, I am a beginner in this area...Thank you very much ahead of time!!
I think you have two options to talk to mongo :
1) Use the rest interface http://www.mongodb.org/display/DOCS/Http+Interface
2) Use Objective-C driver: https://github.com/timburks/NuMongoDB
If you're not completely tied to MongoDB, have a look at CouchDB. It's essentially the same thing as MongoDB (JSON document store) but for the web. They have a nice built-in REST interface which makes database interaction in mobile/server environments very nice.
http://couchdb.apache.org/
In addition to Sid's options, you can also build your own backend that talks to mongodb, that communicates via REST (in your language of choice). This way you can pool your connections on the backend and avoid connectivity issues from the devices.

How to access remote MySql database from iPhone App

I am trying to access a remote MySql database from my iPhone application. I googled, but I can't find anything that works. Can any one suggest a clear way to do this?
Since the iOS SDK does not contain any API's that can access a MySQL database, you have two options:
Implement whatever is necessary in order to talk to a MySQL database engine.
Talk to an application sitting in between your iOS application and your MySQL database.
Of the two, nbr. 2 is by far the easiest, and the normal way to do that is to set up a web service somewhere that you can talk to.
You will have to implement web service methods for whatever kinds of operations you need to perform on your MySQL database.
Exactly how to talk to that web service, and exactly how to talk to the MySQL server from your web service, those are separate questions.

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

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

Connecting to a MySQL database using Xcode and Objective-C

I have been interested in working with a MySQL database in my iPhone or Mac projects. How is a connection performed in Objective-C?
I only had a bit of experience with PHP, but heck, that is a bit too different =/
Check this tutorial for connectivity with SQLite.
You will not be able to connect to MySQL directly from the iPhone. You must use some intermediate layer such as a Web application with PHP.
So, you will have something like this:
iPhone POSTING a request to the WebServer using HTTP
Web Server connecting to the MySQL database
Web Server returning data to the iPhone (XML, plain text)
iPhone processing the data
You can use this technique to query and insert/update/delete data.
Once I found this library for MySQL, and I am aware how it works.
It's a much better option not to deal directly with MySQL, but use Apple's Core Data API.
It allows you to manage an relational database without having to write SQL. It's very fast, very useful. Good stuff.
Try absrd which recycles connections across concurrent threads (queues).
If you want to connect to a MySQL database, use MySQL's Connector/C API library which, as Objective-C is a strict superset of C, you can use without any issues. I helped someone with the installation of it here.

How to connect to a Remote Database from native Iphone app

I want to connect to a remote database(MySQL or SQL Server or Oracle) via internet from my native iphone app. I can't find any API or Framework in System to add. does any one know how to connect to a remote Database? pleased help me. Thank you very much
I'm not an iPhone programmer, but I would suspect you want some abstraction going on.
Instead of trying to make a native database connection work, consider writing some service layer that talks to the database on the back-end, and speaks HTTP to your client application.
Plenty of very good reasons for this. Security concerns chief among them.
One way to do it would be to setup an HTTPS server that wraps your requests. Submit your queries via HTTPS POST. The server setup would be pretty basic and it gives you the chance to do any post-processing before sending it over the wire.
The best alternative is to use webservices to access the information stored remotely.
Bye.
Disclaimer : Shamelessly plugging my own product :)
We've built an online system called Kumulos that allows iOS and OSX developers to build and host online databases in the cloud, while easily creating custom API methods for accessing it. It even builds all the Objective-C bindings for you.
Its really really easy to use and its free while in Beta. We'd love some honest developer feedback :)
Check it out here