iPhone sdk php veri alma

0 Cevap 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";
    }

  ?>

Xcode diğer kısmı:

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

ancak konsol sadece döndürür ....

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

0 Cevap