<?php
class MySQLDao {
var $dbhost = null;
var $dbuser = null;
var $dbpass = null;
var $conn = null;
var $dbname = null;
var $result = null;
function __construct() {
$this->dbhost = Conn::$dbhost;
$this->dbuser = Conn::$dbuser;
$this->dbpass = Conn::$dbpass;
$this->dbname = Conn::$dbname;
}
public function openConnection() {
$this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
if (mysqli_connect_errno())
echo new Exception("Could not establish connection with database");
}
public function getConnection() {
return $this->conn;
}
public function closeConnection() {
if ($this->conn != null)
$this->conn->close();
}
public function getUserDetails($Facebookid)
{
$returnValue = array();
$sql = "select * from Users where FacebookId='" . $Facebookid . "'";
$result = $this->conn->query($sql);
if ($result != null && (mysqli_num_rows($result) >= 1)) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
}
/* public function getUserDetailsWithPassword($email, $userPassword)
{
$returnValue = array();
$sql = "select id,user_email from users where user_email='" . $email . "' and user_password='" .$userPassword . "'";
$result = $this->conn->query($sql);
if ($result != null && (mysqli_num_rows($result) >= 1)) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
} */
public function registerUser($Facebookid, $firstname, $lastname, $FBpictureURL, $Gender, $UserEmail)
{
$sql = "insert into Users FacebookId=?, firstname=?, lastname=?, FBpictureURL=?, Gender=?, UserEmail=?";
$statement = $this->conn->prepare($sql);
if (!$statement)
throw new Exception($statement->error);
$statement->bind_param("isssss", $Facebookid, $firstname, $lastname, $FBpictureURL, $Gender, $UserEmail);
$returnValue = $statement->execute();
return $returnValue;
}
}
?>
Register.php
<?php
require("Conn.php");
require("MySQLDao.php");
$Facebookid = htmlentities($_POST["Facebookid"]);
$firstname = htmlentities($_POST["firstname"]);
$lastname = htmlentities($_POST["lastname"]);
$FBPictureURL = htmlentities($_POST["FBPictureURL"]);
$Gender = htmlentities($_POST["Gender"]);
$UserEmail = htmlentities($_POST["UserEmail"]);
$returnValue = array();
$dao = new MySQLDao();
$dao->openConnection();
$userDetails = $dao->getUserDetails($email);
if(!empty($userDetails))
{
$returnValue["status"] = "Success";
$returnValue["message"] = "User already exists, so Login";
$returnValue["userid"] = "Test";
$returnValue["firstname"] = "Test";
$returnValue["Gender"] = "Test";
$returnValue["FBPictureURL"] = "Test";
echo json_encode($returnValue);
return;
}
$result = $dao->registerUser($Facebookid, $firstname, $lastname, $FBPictureURL, $Gender, $UserEmail);
if($result)
{
$returnValue["status"] = "Success";
$returnValue["message"] = "New User is registered, so Login";
$returnValue["userid"] = "Test";
$returnValue["firstname"] = "Test";
$returnValue["Gender"] = "Test";
$returnValue["FBPictureURL"] = "Test";
echo json_encode($returnValue);
return;
}
$dao->closeConnection();
?>
preferences:
45.44 ms | 402 KiB | 5 Q