Reputation: 641
I am developing an iPhone app. I want to fetch the database from the remote server and show it in my app, so I want to know whether I should directly connect to the remote MySQL database or if it's recommended to use a third Layer like PHP, ASP.Net, etc. to retrieve the data from the remote database.
Upvotes: 0
Views: 1556
Reputation: 54425
Whilst you can use the MySQL client library on iOS, there are a few reasons I'd recommend using a "third layer" intermediate approach:
Security - Do you really want to embed the database, username and password details in your app? (Even if it's a "SELECT only" account.)
Performance - Why not cache some of the result data if at all possible, rather than relying solely on whatever MySQL database engine you're using. This caching could take place at both ends (the scripting language and local storage on the iOS device for offline use).
For example, depending on load/how often the data changes you could cache the data at web service level (perhaps by storing it in memcached or similar instead of executing a query and hitting the database server every time). Likewise, once you've fetched the data from the web service onto the device, you could cache it there. (Potentially via a local SQLite store, or just serialised arrays, as appropriate.)
Also, if you ever want to use multiple backend database servers, this will be transparent from the app's perspective.
Maintenance - If you communicate the relevant data to your iOS app either via JSON or XML, you'll allow for a reasonable degree of change to your database schema without potentially breaking any existing apps that have been deployed.
Upvotes: 5
Reputation: 7822
You need to create a web service that will expose a set of APIs that are then use by your iPhone app to push/pull data. You may then choose to cache the data locally (on the iPhone) in a sqlite3 database. The most common data transfer formats are JSON and XML.
Upvotes: 1