简体   繁体   English

如何在iOS中连接Amazon RDS

[英]How to connect amazon RDS in iOS

I am making an app in which i was using Amazon Simple db but now i have changed the simple db to amazon rds mysql. 我正在制作一个使用Amazon Simple db的应用程序,但现在我已将简单db更改为Amazon rds mysql。 Simple db had own api and frame works to access the data base and tables in iOS but how to access amazon rds mysql in iOS any idea how to get this done. 简单的数据库有自己的API和框架,可以访问iOS中的数据库和表,但是如何在iOS中访问Amazon RDS mysql的任何想法都无法完成。 They have Amazon have libraries for simple db if there is any other way libaray to use amazon rds in iOS app thanks 他们有亚马逊为简单数据库提供的库,如果还有其他方法可以使libaray在iOS应用中使用亚马逊rds的话,谢谢

Amazon RDS instances are regular MySQL / Oracle / ... databases. Amazon RDS实例是常规的MySQL / Oracle / ...数据库。 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. 有一个适用于Mac OS X和iOS的Mysql C驱动程序(请参阅此问题如何在Mac OS X上安装MySQL Connector / C? )。

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. 如果要从iOS应用程序访问RDS MySQL,则必须在二进制发行版中包含此驱动程序,并使用该驱动程序从代码中公开的功能。

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). 通过API层(位于iOS应用程序和数据库之间的Web应用程序)访问数据库有很多好处。

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 好处是:-解耦:不向客户端应用程序公开数据结构-可伸缩性:使用只读副本或分片时,API可以在整个数据库之间进行负载平衡-安全性:API使您可以强制执行身份验证和授权

I use RDS for my app but I built my own API. 我为我的应用程序使用RDS,但是我建立了自己的API。 It's very fast to do from an EC2 instance (free). 从EC2实例(免费)执行操作非常快。 All you do is install apache, mysql, and I did php. 您要做的就是安装apache,mysql,而我做了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. 那么最快的方法是使用一种PHP框架创建路由,并在您的应用程序上使用RestKit对其进行解码。

Your limitations here are that fact that you don't have a jdbc driver to connect your RDS to your iOS app. 这里的限制是您没有jdbc驱动程序来将RDS连接到iOS应用程序。

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. 因此,您需要做的是构建一个REST服务(这不是一件容易的事),将其放在Elastic Beanstalk上,然后将其连接到RDS实例。 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. 您可以用PHP轻松地进行一些操作(这是我第一次做),但是当我很乐意将WAR文件启动到Elastic Beanstalker中时,我开始研究Java rest方法。 As well as some programs to "map" database tables into Java objects. 以及一些将数据库表“映射”到Java对象的程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM