gpt4 book ai didi

php - 将数据插入mysql - ios

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:24 24 4
gpt4 key购买 nike

我想在我的数据库中存储 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
}

我需要存储文本字段中的电话号码、经度、纬度和时间戳。

再一次问候

最佳答案

使用下面的代码

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

您可以获得状态码为explained in this link

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

状态码定义at this link .

在 POST 命令之后,这表示成功,但响应行的文本部分表示应该知道新创建文档的 URI。

如果连接超时,您应该在调用 connection:didFailWithError: 委托(delegate)方法时看到这一点。

使用 PHP tutorial通过 PHP 将 POST 数据(从 iOS 接收)发送到 MYSQL 数据库。

关于php - 将数据插入mysql - ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12245265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com