使用 Xcode 和 Objective-C 连接到 MySQL 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4858274/
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
Connecting to a MySQL database using Xcode and Objective-C
提问by Voldemort
I have been interested in working with a MySQL database in my iPhone or Mac projects. How is a connection performed in Objective-C?
我一直对在我的 iPhone 或 Mac 项目中使用 MySQL 数据库感兴趣。在 Objective-C 中如何执行连接?
I only had a bit of experience with PHP, but heck, that is a bit too different =/
我只有一点 PHP 经验,但是见鬼,这有点太不同了 =/
回答by KingofBliss
Check this tutorialfor connectivity with SQLite.
查看本教程以了解与 SQLite 的连接。
You will not be able to connect to MySQL directly from the iPhone. You must use some intermediate layer such as a Web application with PHP.
您将无法直接从 iPhone 连接到 MySQL。您必须使用一些中间层,例如带有 PHP 的 Web 应用程序。
So, you will have something like this:
所以,你会有这样的事情:
- iPhone POSTING a request to the WebServer using HTTP
- Web Server connecting to the MySQL database
- Web Server returning data to the iPhone (XML, plain text)
- iPhone processing the data
- iPhone 使用 HTTP 向 WebServer 发布请求
- 连接到 MySQL 数据库的 Web 服务器
- 向 iPhone 返回数据的 Web 服务器(XML、纯文本)
- iPhone处理数据
You can use this technique to query and insert/update/delete data.
您可以使用此技术来查询和插入/更新/删除数据。
Once I found this libraryfor MySQL, and I am aware how it works.
一旦我为 MySQL找到了这个库,我就知道它是如何工作的。
回答by Kenny Wyland
It's a much better option not to deal directly with MySQL, but use Apple's Core Data API.
不直接处理 MySQL 而是使用Apple 的 Core Data API是一个更好的选择。
It allows you to manage an relational database without having to write SQL. It's very fast, very useful. Good stuff.
它使您无需编写 SQL 即可管理关系数据库。它非常快,非常有用。好东西。
回答by Nektarios
If you want to connect to a MySQL database, use MySQL's Connector/C API library which, as Objective-C is a strict superset of C, you can use without any issues. I helped someone with the installation of it here.
如果您想连接到 MySQL 数据库,请使用 MySQL 的 Connector/C API 库,因为 Objective-C 是 C 的严格超集,您可以毫无问题地使用。我在这里帮助某人安装了它。