How to connect an iOS app to a database (mySQL & SequelPro)? - mysql

I'm searching for a way to connect an app with a database, created in Sequel Pro which is connected with a mySQL Server (started over MAMP).
I've already searched for some solutions but there are hundreds of different posts, some said that SQLite will be the only possibility, some others said that CoreData will be perfect.
Now I found a framework called 'MCPKit', but this framework isn't really up-to-date and it looks like Apple itself also recommends CoreData for Data Management. (https://developer.apple.com/technologies/ios/data-management.html)
I'm not familiar with CoreData and I'll be very happy if someone knows an other way to build up the connection.
I try to be as specific as possible but if you already have some questions, please ask.

Connecting to a mysql database IS possible. I did it via php which returned an xml file which my app parsed and stored.
This link also covers this topic as well.
How to connect to a MySQL database from an iPhone?

Core Data is a technology for persisting objects in iOS and is often used as a local database. In fact, the NSPersistentStore is almost always implemented as a SQLite database in iOS. However, if you are looking to make network calls to get data from the database on your server, Core Data does not do that.
The short answer is that you need to build a web service on your server that allows you to access the data. A good way (though certainly not the only way) to handle the communications between your service and mobile device is with sockets. Here is a tutorial that can get you a good start.

CoreData actually uses SQLite...
You can access your database with an NSURLRequest, then creating a NSData with the request.
Depending on the format which your Server gives you back (i.e. JSON) you can transform the NSData into a Dictionary. This would look like this with JSON:
NSDictionary *contentDictionary = [NSJSONSerialization JSONObjectWithData:contentServerResponse options:NSJSONReadingMutableContainers error:nil];
then you can access the Dictionary usual Key-Value-Access and assign the content to your ViewController.

If you are using MAMP try writing php script files to access the mySQL db and echo it as JSON text using json_encode function in PHP. You have many parsers to parse JSON in iOS.

Related

Accessing a MySql DB via an IOS application

looking for some advice on a couple of topics.
Im currently starting writing my first IOS application and have some questions.I wish to access some data from a mysql DB - this will hold hold a user table with logins and passwords, etc,...
Can i access the DB directly from IOS and perform my sql queries from within?
What is the standard way of encrypting a cached password for an application?
Is it best practice to perform all the queries from with the app or rely on a web server to proceess these and return the results?
Many thanks, apologies if a little vague but appreciate any constructive feedback guys.
thanks.
Steve
Yes you can access db directly but this isn't ideal. Would be a better idea creating a rest api. Slim framework. Example below:
<?php
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
http://www.slimframework.com/
Would do the processing on the server and then just return a json object or xml you can then do what you want with the data.
Encrypting password you could store in keychain only your app will have access.
Can i access the DB directly from IOS and perform my sql queries from within?
reply : this is good pactice .
What is the standard way of encrypting a cached password for an application?
reply: you can use many encrypting , has md5 ,etc
Is it best practice to perform all the queries from with the app or rely on a web server to proceess these and return the results?
reply: yes you can use any webservice , json or xml it best for ios dev with webservice
You can access a database directly from the iOS using the MySQL C API. I haven't got this to work yet, but you can read more about it here: http://zetcode.com/db/mysqlc/
and
http://dev.mysql.com/doc/refman/5.0/en/c-api-function-overview.html
If you don't get it to work then you can indirectly connect to to MySQL via a PHP server. There are lots of these kind of tutorials out there.
Otherwise you could use SQLite that is bult in. But that's almost a different thing.

How to exchange data between MySQL and Parse.com?

We plan to use a MySQL database as the backend for our (Java or Ruby on Rails) based web application. After completing the web application, we want to port the application to iOS and Android.
We want to be able to run the application in "native" mode - that is, if a network connection is not available to the smart-phone, the system should be able to store the data locally, and sync with the backend when the network connection becomes available.
The best kind of framework for this kind of syncing is a library/framework such as Parse.com.
The question to which we want an answer is: is it possible to exchange data between the web application data stored in MySQL, and the Parse.com data which is stored in a proprietary format on the Parse servers?
Answer to your question: It is indeed possible, but syncing data is an advanced topic.
However, you also state that you want to access the parse data when offline. As I understand it, you want Parse to handle the offline state, and then sync to MySQL when connection is back up. Parse does not offer functionality to store data offline, other than caching requests. You probably need another service for your specific needs.
I might have misunderstood the use case. If so, my alternate understanding would be that ALL data for the smart phones will be handled by parse: both offline and online, with syncing. The answer is still: parse does not offer this kind of functionality.

MySQL and Core Data in iOS

I want to retrieve data from remote MySQL database and store the data in my iOS app (creating "local" database, so the information can still be accessed even though there is no connection). After doing some research, Apple's Core Data API seems to be the answer. However, it's using SQLite.
Can I use Core data with MySQL? If the answer is no, is there any way to develop "local" database other than Core Data? I tried looking for the answer, but no luck. This is the closest one that I can get, but I don't really understand the answer. I am new at iOS development, so any help is greatly appreciated.
Yes, you can use Core Data with MySQL if you like, but you need to write the persistent store functionality yourself, which is a fairly advanced undertaking. It doesn't seem to have any benefits though. I think it would be better to retrieve the data from the MySQL server, and then store it locally in Sqlite. MySQL requires a separate server so obviously it cannot be run locally on iOS anyway.
You cant use coredata with MySQL. Because CoreData is a local database inside the mobile and MySQL is WebServer database. So we cant combine them. Why you dont like CoreData? It is the most powerful and simple database for the mobile apps. I think CoreData suits for your purpose. If your data is something lightweight. Then you can use
Plist
http://hayageek.com/plist-tutorial/
http://www.theappcodeblog.com/2011/05/30/property-list-tutorial-using-plist-to-store-user-data/
NSCoder
http://www.raywenderlich.com/1914/nscoding-tutorial-for-ios-how-to-save-your-app-data
CoreData is the way to go. CoreData is build under SQLLite but it is a relational data base --> Object Oriented mapping which makes it really convenient.
There's a graphic editor which will allow you to define your CoreData model the way you require it.

MySQL wrapper for ios

I am working on my first iOS-application and I want to use MySQL as my remote database.
I've been googing around and reading here at Stack, but I can't find my new answers to the question. Does there exists any good wrappers out there? I found this link: mysql for ios, but it clearly states that it is not guaranteed to be accepted in the App Store.
I really want to have a wrapper rather than using some sort of webservice.
Anyone have some more updated news on this?
Your best bet is to use SQLite or CoreData libraries, they are very low overhead. CoreData is built into iOS functionality, SQLite just needs the .db file and a library (part of iOS) imported.
If you could somehow get your MySQL database online and expose it via REST you could possibly use REST to get and set data into and out of the database. But this will slow your app to a crawl.
CoreData is fast, and when using the data in context like that, it simplifies everything. Writing SQL statements is slowly becoming an archaic process.

Develop an iOS App that gets contents from a remote DB

I am developing an education app for Kids.
The application is going to contain pictures, stories and video as well.
Including all above contents in the app will surely bloat it and hence i would like store all data on a server that will be accessed by my app.
I haven't used any remote databases (like MySQL or Oracle) with any other iOS app. In fact i am a newbie in developing such kind of apps. Can any one point me to a sample
Connecting to a remote mysql is really not recommended.
The security here is critical.
You should create a webservice and my advice to you is to make sure that the access to the webservice is restricted
The webservice can be your own "protocol" or any other well known protocol like SOAP
By your own I mean, json, csv .... or whatever.
Edit 1
The technology of your webservice should be dependent on many things.
If the system is small, and the code needs to be update very often, I would suggest to do it with PHP and some small(!) MVC framework like CI.
But if its a large system with needs of ACL (access control list) I will probably choose java with spring...
I suggest that : Do not connect to / use database directly from user application. It may causes serious security problems and your app should have native SQL drivers to connect db.
So, create a web service that receive queries from the application and response in XML, JSON or some other strings that easy to parse. This will be much easier than embed native APIs into your apps.