Saturn
Saturn

Reputation: 18159

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

Upvotes: 8

Views: 45662

Answers (4)

Nektarios
Nektarios

Reputation: 10351

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.

Upvotes: 1

hernan saab
hernan saab

Reputation: 9

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

Upvotes: 1

KingofBliss
KingofBliss

Reputation: 15115

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.

Upvotes: 13

Kenny Wyland
Kenny Wyland

Reputation: 21880

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.

Upvotes: 3

Related Questions