/** * Save a newly created user to database * * @param User $user * @return bool */ public function save(User $user) { //construct a sql statement $sql = 'INSERT INTO users (username, password, usernames,token, token_expire) VALUES(?,?,?,?,?)'; //connect to the database $connection = $this->getConnection(); //prepare a statement $statement = $connection->prepare($sql); /* * I have to get the object properties here because, apparently * PDOStatement::bindParam() does not allow passing of objects by reference, sad * stuff. */ $username = $user->getUsername(); $password = $user->getPassword(); $names = $user->getNames(); $token = $user->getToken(); $tokenExpire = $user->getTokenExpire(); //bind params to statement $statement->bindParam(1, $username); $statement->bindParam(2, $password); $statement->bindParam(3, $names); $statement->bindParam(4, $token); $statement->bindParam(5, $tokenExpire); //execute query $statement->execute(); //check to see if user was saved if ($statement->rowCount() > 0) { return true; } throw new PDOException("Error: Record not saved. Please try again"); }