8

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 =/

2
  • 2
    Are you sure you mean MySQL and no SQLite which is usually use for mobile/desktop applications? Commented Feb 1, 2011 at 2:26
  • Hmm... I would like to hear more about that too, then. Thank you. Commented Feb 1, 2011 at 2:28

4 Answers 4

13

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:

  1. iPhone POSTING a request to the WebServer using HTTP
  2. Web Server connecting to the MySQL database
  3. Web Server returning data to the iPhone (XML, plain text)
  4. 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Re: You will not be able to connect to MySQL directly from the iPhone. >> This isn't exactly true. I have a working version of MCPKit connecting to a remote MySQL database. But your suggestion about using a PHP/web intermediate layer is a great recommendation.
Here is the updated link to donwload mysql Library: eval-art.com/2009/06/22/mysqlframework-for-iphone
3

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.

1 Comment

Technically Core Data is not a relational database but rather an object graph manager (if you want to get technical).
1

Try absrd which recycles connections across concurrent threads (queues).

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.