0

データベースに 4 つの値を保存したいと思います。経度、緯度の電話番号とタイムスタンプ。

NSLOGを使用してローカルに保存する方法を理解しました。

しかし、それをMySQLデータベースに送信したい.

誰かがチュートリアルを持っているか、ここで私を助けたいですか?

私はこれがひどく必要です、

あなたの助けをいただければ幸いです。

あいさつ

アップデート

データベースに保存する必要があるコードは次のとおりです

    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
}

そして、テキストフィールド、経度、緯度、タイムスタンプから電話番号を保存する必要があります。

ごあいさつ(改めて)

4

3 に答える 3

2

次のコードを使用します

  //Create String
    NSString *var1 =@"waitTime=";
    NSString *var2 =@"&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];

このリンクで説明されているように、ステータス コードを取得できます。

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

ステータス コードは、このリンクで定義されています。

POST コマンドに続いて、これは成功を示しますが、応答行のテキスト部分は、新しく作成されたドキュメントを認識するための URI を示します。

接続がタイムアウトした場合、connection:didFailWithError: デリゲート メソッドが呼び出されたときにこれが表示されます。

PHP チュートリアルを使用して、(iOS から受信した) POST データを PHP 経由で MYSQL データベースに送信します。

于 2012-09-03T10:13:49.040 に答える
1

これは役に立ちましたか?

INSERT INTO table_name (column1, column2, column3,...)
 VALUES (value1, value2, value3,...)
于 2012-09-03T09:35:02.360 に答える
1

まあ、あなたが何を望んでいるのかわかりませんが、一般的に理解しているように、mysqlサーバー上のローカルデータを更新したい場合は、簡単なことをするだけです

ASIHTTPrequest または AF および sbjeson フレームワークを追加し、ur データを json にエンコードし、post または get メソッドを使用して php ページに送信します。このページで、php は辞書を連想配列としてデコードし、ループして mysql に更新するだけです。

データを保存したいだけなら、Codedataまたはsqliteを使用する必要があります。

于 2012-09-03T10:08:13.250 に答える