简体   繁体   English

xcode使用PhP更新mysql远程数据库

[英]xcode updating mysql remote database using PhP

I have been following this great tutorial and got my codes to working with most of the database transfers. 我一直在遵循这个出色的教程,并获得了处理大多数数据库传输的代码。 Now I'd like to use the same method to update long text messages and images onto my server MySQL database, but it doesn't seem to work. 现在,我想使用相同的方法将长文本消息和图像更新到我的服务器MySQL数据库上,但似乎不起作用。

NSString *strURL = [NSString stringWithFormat:@"http://mydomain.com/sync.php?name=%@&message=%@&image=%@",nameField.text, messageField.text, image];

and then 接着

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"StrResult is... %@", strResult);

Problem 1: When the messageField.text is a long text with blank spacing in between such as "This is a free text format with up to 1000 characters..." , it will cause strURL to have blank spaces as well, and thus strResult will become null. 问题1:当messageField.text是一个长文本且之间有空格时,例如“这是一种自由文本格式,最多可包含1000个字符...” ,这将导致strURL也具有空格,从而导致strResult将变为空。

Problem 2: image is of blob format which I already saved in the local sqlite. 问题2: 图像具有Blob格式,我已经保存在本地sqlite中。 I'm not even sure if transferring this way is a good idea. 我什至不确定以这种方式转移是否是个好主意。 But basically I want to upload the image from iPhone/iPad straight onto a server MySQL database. 但基本上我想将图像从iPhone / iPad直接上传到服务器MySQL数据库中。

Hope someone could help me with either one of these 2 problems. 希望有人可以帮助我解决这两个问题之一。 Or are there any better and easier alternatives to update MySQL on my server? 还是有更好更好的替代方法来更新服务器上的MySQL? Thank you! 谢谢!

Problem 1 : When you are sending parameters through a GET request, you need to escape your parameters to avoid illegal characters. 问题1:通过GET请求发送参数时,需要转义参数以避免非法字符。 By the way, you can not send unlimited data with this kind of request. 顺便说一句,您不能通过这种请求发送无限的数据。 For a large amount of data, you should rather use a POST request. 对于大量数据,您应该使用POST请求。

Problem 2 : ASIHTTPRequest is a wrapper used to communicate with remote servers. 问题2: ASIHTTPRequest是用于与远程服务器通信的包装器。 If you choose to use it (I encourage you to do), here is the documentation that you will need to POST a request . 如果您选择使用它(建议您这样做),那么这里是您发布POST请求所需的文档。 There is also an example to send an image to a remote server with NSData. 还有一个使用NSData将映像发送到远程服务器的示例。

Problem 1: there's a lot of ways to do this... one of them are when you put it into the database do this: 问题1:有很多方法可以执行此操作...其中之一是当您将其放入数据库时​​执行此操作:

messageField.text = [messageField.text stringByReplacingOccurrencesOfString:@" " withString:@"_"];

Maked the text: "This is a free text format with up to 1000 characters..." to: "This_is_a_free_text_format_with_up_to_1000_characters..." 将文本输入:“这是一种自由文本格式,最多可包含1000个字符...”,将其显示为:“ This_is_a_free_text_format_with_up_to_1000_characters ...”

And then when you take it out of the database again use the code opposite: 然后,当您再次将其从数据库中取出时,请使用相反的代码:

messageField.text = [messageField.text stringByReplacingOccurrencesOfString:@"_" withString:@" "];

That makes it from: "This_is_a_free_text_format_with_up_to_1000_characters..." to "This is a free text format with up to 1000 characters..." 这使得它从“ This_is_a_free_text_format_with_up_to_1000_characters ...”到“这是一种最多包含1000个字符的自由文本格式...”

But remember thats one way to do it... you can also replace the "_" with Something else like" I " or whatever you want.. something the user won't type... 但是请记住,这是一种实现方式...您也可以将“ _”替换为“ I ”之类的东西或您想要的任何东西..用户不会输入的内容...

Problem 2: I don't know a lot about databases and images.. but se this: Blob 问题2:我对数据库和图像了解不多..但是: Blob

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM