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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saturn
  • 17,888
  • 49
  • 145
  • 271

4 Answers4

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
KingofBliss
  • 15,055
  • 6
  • 50
  • 72
  • 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. – mattlangtree Jul 11 '12 at 00:27
  • Here is the updated link to donwload mysql Library: http://www.eval-art.com/2009/06/22/mysqlframework-for-iphone/ – João Nunes Apr 04 '14 at 07:47
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.

Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
  • 1
    Technically Core Data is not a relational database but rather an object graph manager (if you want to get technical). – walkingbrad Apr 26 '13 at 03:21
1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nektarios
  • 10,173
  • 8
  • 63
  • 93