将 iPhone 应用程序与 MySQL 数据库连接的教程?(Objective-C 与 mysql 的接口)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9645320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tutorial to Connect iPhone app with MySQL database? (Interface Objective-C with mysql)
提问by Dylan
I am looking for a tutorial on how to make an iPhone app that fetches data from and writes data to a MySQL database. I've seen some other threads saying that I should make an abstraction layer so as not to connect directly to the database from my app, but I'm not sure of how to actually go about doing this. Does anyone know of any tutorials that involve creating an abstraction layer for a MySQL database or connecting a MySQL database to an iPhone app?
我正在寻找有关如何制作从 MySQL 数据库获取数据并将数据写入到 MySQL 数据库的 iPhone 应用程序的教程。我看到其他一些线程说我应该创建一个抽象层,以免从我的应用程序直接连接到数据库,但我不确定如何实际执行此操作。有谁知道任何涉及为 MySQL 数据库创建抽象层或将 MySQL 数据库连接到 iPhone 应用程序的教程?
To clarify, I am looking for a secure method that wouldn't allow people to sniff out my MySQL host, username and password. It seems like the libraries that connect directly to MySQL from the iPhone all have this problem, but please correct me if I'm wrong.
澄清一下,我正在寻找一种安全的方法,不会让人们嗅出我的 MySQL 主机、用户名和密码。从 iPhone 直接连接到 MySQL 的库似乎都有这个问题,但如果我错了,请纠正我。
回答by Tomasz Wojtkowiak
I know only one library, which makes possible connection from iPhone to MySQL. This is port of official MySQL C libraries created by Karl Kraft.
Author published also small portion of samples, which describes how to use this library.
我只知道一个库,它使从 iPhone 连接到 MySQL 成为可能。这是Karl Kraft创建的官方 MySQL C 库的端口。
作者还发布了一小部分示例,描述了如何使用该库。
UPDATE (Karl Kraft's broken link)
更新(Karl Kraft 的断开链接)
Instead of link above, I used an archived copy.
我没有使用上面的链接,而是使用了存档副本。
回答by Snowman
This is a really good tutorial that covers how to communicate with MySQL from an iPhone app using PHP:
这是一个非常好的教程,涵盖了如何使用 PHP 从 iPhone 应用程序与 MySQL 通信:
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
回答by Tristan G
not up to date, but this tutorial helped me a lot: http://codewithchris.com/iphone-app-connect-to-mysql-database/#connectiphonetomysql
不是最新的,但本教程对我帮助很大:http: //codewithchris.com/iphone-app-connect-to-mysql-database/#connectiphonetomysql
回答by Oleg
回答by David Agustin Almanza Gaitan
Hereis a nice tutorial on how to connect to a database using web service layer. From a practical perspective you could connect directly to a database from an iphone because that is a client server transaction. The problem is that you would need to expose your database server an issue that many would find very disturbing, because you would expose your server which hold your most valuable resource "your data". Of course you can implement and could be a good solution for rather small projects. But you would need to implement the layer which it would be used to connect on the iOS app, adding more complex to the matter.
这是一个关于如何使用 Web 服务层连接到数据库的很好的教程。从实用的角度来看,您可以直接从 iPhone 连接到数据库,因为这是客户端服务器事务。问题是您需要公开您的数据库服务器一个许多人会觉得非常令人不安的问题,因为您将公开您的服务器,其中包含您最宝贵的资源“您的数据”。当然,您可以实施,并且对于相当小的项目来说可能是一个很好的解决方案。但是您需要实现它将用于在 iOS 应用程序上连接的层,从而使事情变得更加复杂。
Using a web service is more reliable even from the iOS developer, because there is a very extensive api for using web service, which offer great functionality (asynchronous transactions, threads management,JSON Mapping, XML Mapping) to name a few.
即使对于 iOS 开发人员,使用 Web 服务也更加可靠,因为有一个非常广泛的用于使用 Web 服务的 api,它提供了强大的功能(异步事务、线程管理、JSON 映射、XML 映射)等等。
回答by p?t
Here http://blog.iosplace.com/?p=30is a snippet that uses the original mysql client lib, and here http://www.karlkraft.com/index.php/2012/01/is a link to a 3rd-party connector.
这里http://blog.iosplace.com/?p=30是一个使用原始 mysql 客户端库的片段,这里http://www.karlkraft.com/index.php/2012/01/是一个链接到第 3 方连接器。