Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data and MySQL

How would I create a core-data application that syncs with a MySQL database?

Should I implement a SQL-Lite layer and try to sync with MySQL that way?

Or would running web services be better? I want to take advantage of Core Data modeling though.

Is there any way to use Linq? I love linq.

like image 603
Bryan Avatar asked Dec 08 '25 08:12

Bryan


1 Answers

I'm a PHP/MySQL programmer in my day job, and the easiest way I could think of to get data out of MySQL for my Core Data app was to make a HTTP connection to a PHP web server which returned the data in plist xml format. Then I can easily fill an NSArray using the plist data.

For example, this was how I did it in my app:

NSURL *url = [NSURL URLWithString:@"http://myphpwebsite.com/products"];
NSArray *products = [[NSArray alloc] initWithContentsOfURL:url];

Then I had an NSArray of products that I used in my app and persisted to Core Data.

I always recommend that people use PHP, Apache and MySQL together. They work great together on the backend, almost seamlessly. For example, I can easily get data out of MySQL using PHP. Then I can manipulate that data in PHP into the plist xml format used by my iPhone app.