【发布时间】:2013-04-13 06:44:08
【问题描述】:
我想使用 NSURLConnection 从 PHP/Mysql 请求中获取一个值(可以是 1 或 0),下面是我的 xcode 和 php/mysql 查询代码
谁能帮我将接收到的数据存储在 NSString 而不是 NSMutableData 中? 我之所以要使用 NSURLConnection 是因为它提供了无连接功能
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.20/iqkradio_stream_ip_flag.php"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
NSString *receivedDataString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
}
else
{
NSLog(@"no connection or Error");
// Inform the user that the connection failed.
}
Mysql 文件
<?php
$con = mysql_connect("192.168.0.15","xxxx","xxxxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("qkradio", $con);
$result = mysql_query("select address from iqkradio" );
while($row = mysql_fetch_array($result)) {
echo $row['address'];
}
mysql_close($con);
?>
【问题讨论】:
标签: php mysql xcode nsurlconnection