2012-09-03 98 views
0

我想在我的數據庫中存儲4個值。經度,緯度電話號碼和時間戳。插入數據到mysql - ios

我明白了人想出如何將它們與本地的存儲的NSLog,

但我想將它發送到我的MySQL數據庫。

有人有一些教程或想幫助我嗎?

我需要這個不好,

您的幫助,將不勝感激。

電賀

UPDATE

下面是一些代碼,我需要在我的數據庫

resultsLabel.text = [NSString stringWithFormat:@"(%@) %@ Location %.06f %.06f %@", ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ? @"bg" : @"fg", resultsLabel.tag == 0 ? @"gps:" : @"sig" , newLocation.coordinate.latitude, newLocation.coordinate.longitude, [formatter stringFromDate:newLocation.timestamp]]; 

LocationTestAppDelegate * appDelegate = (LocationTestAppDelegate *)[UIApplication sharedApplication].delegate; 
[appDelegate log:resultsLabel.text]; 

NSString* encodedValue = [newLocation.coordinate.latitude 
          stringByAddingPercentEscapesUsingEncoding: 
          NSASCIIStringEncoding]; 

//construct an URL for your script, containing the encoded text for parameter value 
NSURL* url = [NSURL urlWithString: 
       [NSString stringWithFormat: 
       @"http://yourdomain.com/locatie.php?id=%@", 
       encodedValue]]; 

NSError* error = nil; 
//send the request synchronously, store the response in result 
NSString* result = [NSString stringWithContentsOfURL:url 
              encoding:NSUTF8StringEncoding 
               error:&error]; 

if (!error && ([result isEqualToString:@"OK"])) { 
    // everything went well 
} 

存儲,我需要從一個文本框,經度,緯度&時間戳存儲的電話號碼。

迎接(再次)

+1

http://whathaveyoutried.com? – Luke

+0

我試圖做SQLite,但直到現在,這是行不通的。 –

+0

如果你發佈代碼,那麼人們更有可能協助修復它並幫助你。 ;) – Luke

回答

1

對您有幫助嗎?

INSERT INTO table_name (column1, column2, column3,...) 
VALUES (value1, value2, value3,...) 
+0

嗯,我需要PHP代碼和IO代碼來實現它在我的應用程序 –

1

好吧,我不知道你想要什麼,但正如我在GENRAL理解,如果你要更新的MySQL服務器上的本地數據,那麼你剛剛做簡單的事情

添加ASIHTTPrequest或AF和sbjeson框架並將你的數據編碼到json中,並用post或get方法發送到php頁面,其中php可以將字典解碼爲關聯數組,然後循環並更新到mysql。

如果你只是想存儲數據,那麼你應該使用Codedata或sqlite。

2

使用下面的代碼

//Create String 
    NSString *var1 [email protected]"waitTime="; 
    NSString *var2 [email protected]"&cover="; 
    NSString *wait = [var1 stringByAppendingString:waitTime.text]; 
    NSString *co = [var2 stringByAppendingString:cover.text]; 


    NSMutableURLRequest *request = 
    [[NSMutableURLRequest alloc] initWithURL: 
    [NSURL URLWithString:@"http://mysite.net/index.php"]]; 

    [request setHTTPMethod:@"POST"]; 

    NSString *postString = [wait stringByAppendingString:co]; 

    [request setValue:[NSString 
         stringWithFormat:@"%d", [postString length]] 
    forHTTPHeaderField:@"Content-length"]; 

    [request setHTTPBody:[postString 
          dataUsingEncoding:NSUTF8StringEncoding]]; 

    [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

你可以得到狀態碼explained in this link

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 
    int code = [httpResponse statusCode]; 
} 

狀態代碼被定義at this link

在POST命令之後,這表示成功,但響應行的文本部分指示應該知道新創建文檔的URI。

如果連接超時,則應在連接:didFailWithError:delegate方法被調用時看到此情況。

使用PHP tutorial通過PHP將POST數據(從iOS接收)發送到MYSQL數據庫。