uiview.controller
let URL_SAVE_BOY = "hoge" @IBOutlet weak var NameFeild: UITextField! @IBOutlet weak var oldFeild: UITextField! @IBAction func saveBtn(_ sender: Any) { let requestURL = NSURL(string: URL_SAVE_BOY) let request = NSMutableURLRequest(url: requestURL! as URL) request.httpMethod = "POST" let teamName = NameFeild.text let memberOld = oldFeild.text let postParameters = "name="+teamName!+"&old="+memberOld!; request.httpBody = postParameters.data(using: String.Encoding.utf8) let task = URLSession.shared.dataTask(with: request as URLRequest){ data, response, error in if error != nil { print("error is \(error)") return; } do { let myJSON = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary if let parseJSON = myJSON { var msg : String! msg = parseJSON["message"] as! String? print(msg) } } catch { print(error) } } task.resume() }
php側
$response = array(); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $teamName = $_POST['name']; $member = $_POST['old']; } $dsn = "mysql:dbname=db;host=hostname"; $user = "username"; $password = "pwd"; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e){ print('connection failed:'.$e->getMessage()); } $sql = "insert into swift (name, member) VALUES (:name, :member)"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':name', $teamName, PDO::PARAM_STR); $stmt->bindValue(':member', $member, PDO::PARAM_INT); $stmt->execute(); $response['api'] = "succeeded"; $response['member'] = $member . " years old!"; echo json_encode($response); echo "finish";
エミュレーターでyyyy, 55と入れます。
DB側
今回は,phpadmin
ちゃんと入っています。
次は、
1.mysqlからfetch。
2.配列をtable viewから表示
3.ec2から接続する
4.androidのDB接続
5.photoshopのエレメントをxcodeに乗せてく
6.app構築
7.app storeに申請
ってところか。
う〜、、、やること思ってたより多い。