iOS Xcode connecting to MySQL database

孤街醉人 提交于 2020-01-29 02:14:08

问题


I'm currently making an iOS App for my school, and have no previous experience with iOS programming. However, I do have experience with HTML/PHP/MySQL.

Currently we have a basic tab bar application with 5 tabs at the bottom. Obviously, since this is an app for a school, it needs to be dynamic and hopefully we can set something up to connect to a database and retrieve school lunch menus, and news.

I know how to connect to a database normally with PHP, but I have no idea how to do it using the current version of Xcode. I've done research and apparently I need to use a webservice and json to safely get the information from the database.

Does anyone have any links for me to get started, because I have no experience at all with this program. I don't need to be spoonfed, but a point in the right direction would help. I really can't find any links for this new version of Xcode.


回答1:


Here are two great tutorials that helped me a lot

How To Write A Simple PHP/MySQL Web Service for an iOS App

How to Write an iOS App That Uses a Web Service




回答2:


There are no "over the air" APIs that will let you connect directly to a MySQL database. Instead, what you could do is create a RESTful web service in front of the database that returns the data as JSON via a request from an NSURLRequest object.




回答3:


By normally connection via PHP, what you actually mean is you had done web development. This means there was a server, and a database.

There's no available server in the iOS runtime that will allow you to install PHP or MySQL.

You can't do it...

But, you could make your php and database on a server, and connect to it via the network from your app.

My suggestion is to look what kind of database you need, if it's for school and it isn't really interactive with the outside world, then use SQLite in your app, it's an embedded database so it's on the phone, as quick as you can want, no networking and you can obviously leverage your SQL knowledge.

If you want to make an API or, server with your php things, you really are giving yourself a lot of extra work.




回答4:


You need to create an NSMutableURLRequest and initialize an NSURLConnection with it to send an HTTP message. Something like that:

NSURL *url = [NSURL URLWithString:@"http://xyz.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];


来源:https://stackoverflow.com/questions/13401937/ios-xcode-connecting-to-mysql-database

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