모두에게.PHP를 통해 iOS에 MySQL 레코드 보내기
저는 PHP를 통해 MySQL에 연결하는 내 iOS 응용 프로그램과 함께 작업하고 있습니다.
내 앱이 PHP GET 요청을 보내고 MySQL 데이터베이스에서 선택된 일부 데이터를 가져오고 싶지만 MySQL에서 iOS로 데이터를 보내는 방법을 모른다. 여기 내 코드가있다.
myDataGetter.m
//create a request and connect (url is my PHP file's)
NSURLRequest* getRequest = [NSURLRequest requestWithURL:url];
NSURLConnection* connection = [NSURLConnection connectionWithRequest:getRequest
delegate:self];
if (connection) {
//data received from PHP will be stored in receivedData
receivedData = [[NSMutableData alloc] init];
} else {
//error
}
내 NSGRLConnection의 대리자 메서드를 설정했습니다. 예를 들어,
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[receivedData setLength:0]
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
}
내 PHP 파일
,이 예에서$con = mysql_connect ('host', 'user', 'pass');
mysql_select_db ('dbname', $con);
$rows = mysql_query ("SELECT name, age, email FROM table");
while ($row = mysql_fetch_array ($rows)) {
$name = $row["name"];
$age = $row["age"];
$email = $row["email"];
}
, 나는 아이폰 OS에 $ 이름, $ 연령, 및 $ 이메일을 보내려고합니다. 이 작업을 수행하는 방법을 알고 있다면 나를 도와주십시오.
감사합니다.
어디 U는 PHP 서버와 연결 아이폰을 만들 수 있습니까? – Sergey
@Sergey 귀하의 의견을 보내 주셔서 감사합니다! UIViewController의 Subclass 인 myDataGetter.m에 연결을 작성했습니다. 같은 ViewController에서 나는 addSubView : UIButton을 만들었고 터치했을 때 그것을 터치하면 연결이 시작됩니다. – nakazy