I tried to fetch an array from my prepared statement using fetch_assoc()
but PHP is throwing an error:
Call to undefined function fetch_assoc()
How can I retrieve an array from the prepared statement?
public function createUser($name, $email, $pass) {
require_once 'PassHash.php';
$api_key = uniqid('', true);
$passwordHash = PassHash::hash($pass); // hash password
$stmt = $this->conn->prepare("INSERT INTO `users`(`name`, `email`, `password`, `api_key`, `friends`)
VALUES(?, ?, ?, ?, 0)");
$stmt->bind_param("ssss", $name, $email, $passwordHash, $api_key);
$result = $stmt->execute();
$stmt->close();
// check for successful store
if ($result) {
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmtStore = $stmt->store_result();
$user = fetch_assoc($stmtStore);
$stmt->close();
return $user;
} else {
return false;
}
}