iphonesdk从php获取数据
我的iPhone应用程序有问题。 我想读一个mysql数据库,一种方法是通过php提供数据。 我的php文件如下所示:iphonesdk从php获取数据,php,iphone,xcode,Php,Iphone,Xcode,我的iPhone应用程序有问题。 我想读一个mysql数据库,一种方法是通过php提供数据。 我的php文件如下所示: <?php $db_verbindung = mysql_connect("localhost", "root","") or die ("Keine Verbindung moeglich"); $db = mysql_select_db("testdb") or die ("Die Datenbank existiert nicht.")
<?php
$db_verbindung = mysql_connect("localhost", "root","") or die
("Keine Verbindung moeglich");
$db = mysql_select_db("testdb") or die
("Die Datenbank existiert nicht.");
$querystring = $_POST['querystring'];
$result = mysql_query($querystring) or die(mysql_error());
$theString;
while ($row = mysql_fetch_object($result)) {
$theString .=$row->productName."\n";
}
?>
但控制台只返回
打开Xcode中的断点来构建和调试。现在它不会终止,而是挂起并显示错误所在的位置(以及内容)。
请发布从控制台获得的响应。尝试在PHP脚本底部打印$theString。您正在构建变量,但从未输出它 在“?>”之前,说
echo$theString代码>
可能还有其他事情发生;当我看到这一点时,我停止了挖掘
NSString *post = @"querystring=select productID, productName from products";
NSData *postData = [post dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO];
NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[urlRequest setURL:[NSURL URLWithString:@"http://localhost/versionsnews/test.php"]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:postData];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
if(!urlData) {
NSLog(@"Connection Failed!");
}
NSLog(@"Alles klar! empfangen:%d bytes",[urlData length]);
NSString *aStr = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"%@", aStr);