2012-09-03 2 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 코드와 iOs 코드가 필요하다. –

1

그럼 난 당신이 원하는 것을 확실하지 오전하지만 난 genral에서 이해 당신은 MySQL 서버의 로컬 데이터를 업데이트 할 다음 U 그냥

이 ASIHTTPrequest 또는 AF 및 sbjeson 프레임 워크를 추가 간단한 일을 할 경우 ur 데이터를 json에 encode하고 post와 함께 보내거나 php가 associative array로 사전을 디코딩 할 수있는 PHP 페이지로 메소드를 가져 와서 mysql으로 루프하고 업데이트한다.

그리고 u가 단지 데이터를 저장하려면 Codedata 또는 sqlite를 사용해야합니다.

2

당신은 explained in this link

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

상태 코드가 at this link을 정의 된 바와 같은 상태 코드를 얻을 수있는 다음 코드를

//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]; 

를 사용합니다.

POST 명령 다음에 이는 성공을 나타내지 만 응답 행의 텍스트 부분은 새로 작성된 문서를 알려야하는 URI를 나타냅니다.

연결 시간이 초과되면 connection : didFailWithError : delegate 메서드가 호출 될 때 표시되어야합니다.

PHP tutorial을 사용하여 iOS에서받은 POST 데이터를 PHP를 통해 MYSQL 데이터베이스로 보냅니다.

관련 문제