How to connect amazon RDS in iOS

扶醉桌前 提交于 2019-11-28 13:01:05
Sébastien Stormacq

Amazon RDS instances are regular MySQL / Oracle / ... databases. You can connect to it from any device or platform, provided you have a driver for it.

There is a C driver for Mysql (see this question How to install MySQL Connector/C on Mac OS X?) that works on Mac OS X and iOS.

If you want to access RDS MySQL from an iOS application, you must include this driver in your binary distribution and use the functions exposed by the driver from your code.

On an architectural point of view, I however question this approach. There are many benefits to access your database through an API layer (a web application sitting in between your iOS App and the database).

Benefits are : - decoupling : do not expose data structure to client app - scalability : the API can load balance accross DB when using read replica or sharding - security : an API let you enforce authentication and authorisation

I use RDS for my app but I built my own API. It's very fast to do from an EC2 instance (free). All you do is install apache, mysql, and I did php. Then the fastest way is to use one of the PHP frameworks to create routes and use RestKit on your app to decode them.

Your limitations here are that fact that you don't have a jdbc driver to connect your RDS to your iOS app.

So what you need to do is build a rest service(not an easy task), sit it on a Elastic Beanstalk, and connect it to your RDS instance. The apps then hit the rest service through get and post messages. You can use token authentication in your app for security.

You could hack something very easy in PHP(it's what I did my first time), but when I got comfortable launching WAR files into Elastic Beanstalker, I starting looking into Java rest methods. As well as some programs to "map" database tables into Java objects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!