在我的应用程序中,我使用2个php文件,其中一个包含应用程序所需的所有功能,另一个是检索并将数据发送回用户
我的第一个php文件是DB_Functions.php 其中包含以下代码
<?php
class DB_Functions {
private $conn;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$db = new Db_Connect();
$this->conn = $db->connect();
}
/**
* Storing new user
* returns user details
*/
public function storeUser($name,$sex,$dob,$email,$college,$password,$latitude,$longitude,$pass) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$stmt = $this->conn->prepare("INSERT INTO CFLASH_USERS(Name, sex, dob, mail, college, password, latitude, longitude, pass, salt, created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("ssssssssss", $name, $sex, $dob, $email, $college, $password, $latitude, $longitude, $pass, $salt);
$result = $stmt->execute();
$stmt->close();
// check for successful store
if ($result) {
$stmt = $this->conn->prepare("SELECT * FROM CFLASH_USERS WHERE mail = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
return $user;
} else {
return false;
}
}
/**
* Encrypting password
* @param password
* returns salt and encrypted password
*/
public function hashSSHA($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
/**
* Decrypting password
* @param salt, password
* returns hash string
*/
public function checkhashSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
}
?>
我的第二个php文件Register.php包含
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])) {
// receiving the post params
$name = $_POST['name'];
$sex = $_POST['sex'];
$dob = $_POST['dob'];
$email = $_POST['email'];
$college = $_POST['college'];
$password = $_POST['password'];
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$pass = $_POST['pass'];
// create a new user
$user = $db->storeUser($name, $sex, $dob, $email, $college ,$password, $latitude, $longitude, $pass);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["mail"];
$response["user"]["name"] = $user["Name"];
$response["user"]["sex"] = $user["sex"];
$response["user"]["dob"] = $user["dob"];
$response["user"]["email"] = $user["mail"];
$response["user"]["college"] = $user["college"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (name, email or password) is missing!";
echo json_encode($response);
}
?>
我无法将数据插入其中。我已经检查过meathod是错的,但没错。所以我认为bind_param()会出错。请告诉我错误的位置以及纠正错误的解决方案。
请解释一下“调用未定义的方法mysqli_stmt :: get_result()”