开发者

iPhone sdk getting data from php

开发者 https://www.devze.com 2023-01-11 07:28 出处:网络
开发者_开发问答i have a problem with my iPhone application. I want to read a mysql database, one method is to serve the data over php.

开发者_开发问答i have a problem with my iPhone application. I want to read a mysql database, one method is to serve the data over php. My php file looks like this:

 <?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";
    }

  ?>

the other part in xcode:

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);

but the console only returns....

http://img683.imageshack.us/img683/7868/screenmq.png


Try printing out $theString at the bottom of your PHP script. You're building the variable but you're never outputting it!

Before "?>", say echo $theString;.

There may be other things going on; I stopped digging when I saw that.


Turn on the Breakpoints in Xcode to Build and Debug. Now it doesn't terminate but hangs and shows you where (and what) the bug is. Please post the response you get from the console.

0

精彩评论

暂无评论...
验证码 换一张
取 消