iphone iphone如何访问数据库
1:http://www.cocoachina.com/bbs/simple/?t29587.html
我现在用post方式发送的,可以发送中文,并且数据长度没有限制,get方式发送请求时对数据长度有限制的。
下面是post 方式的代码
NSString *post = @"name=admin&password=123456";
NSData *postData=[post dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *connectionRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/test/test.php"]];
[connectionRequest setHTTPMethod:@"POST"];
[connectionRequest setTimeoutInterval:100.0];
[connectionRequest setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[connectionRequest setHTTPBody:postData];
NSData *data=[NSURLConnection sendSynchronousRequest:connectionRequest returningResponse:nil error:nil];
NSString *stringdata=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
下面是post 方式的代码
NSString *post = @"name=admin&password=123456";
NSData *postData=[post dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *connectionRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/test/test.php"]];
[connectionRequest setHTTPMethod:@"POST"];
[connectionRequest setTimeoutInterval:100.0];
[connectionRequest setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[connectionRequest setHTTPBody:postData];
NSData *data=[NSURLConnection sendSynchronousRequest:connectionRequest returningResponse:nil error:nil];
NSString *stringdata=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",stringdata);
调用数据库时,应该执行如下操作:
一般都不会直接连接,而是通过调用Web Service或者POST请求以XML或者JSON的形式把数据传给后台,然后在后台进行数据库的连接处理。