我想通过iPhone应用程序连接到我的网络主机上的MySQL服务器。在android中我使用下面的php页面作为后端,我通过json从设备连接到这个页面并做其他事情,是否有可能在iPhone上?它是一样的吗?
登录:
<?php
require("config.inc.php");
if (!empty($_POST)) {
$query = " SELECT username, password FROM user WHERE username = :username ";
$query_params = array(
':username' => $_POST['username']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error. Please Try Again!";
die(json_encode($response));
}
$validated_info = false;
$row = $stmt->fetch();
if ($row) {
if ($_POST['password'] === $row['password']) {
$login_ok = true;
}
else
$login_ok = false;
}
if ($login_ok == true) {
$response["success"] = 1;
$response["message"] = "Login Successful";
die(json_encode($response));
} else {
$response["success"] = 0;
$response["message"] = "Invalid Credentials!";
die(json_encode($response));
}
}