<?php
class User{
	
	public function insertUserDeviceToken($token, $bdd){
		try{
			$sql  = 'INSERT INTO `firebase` (token)';
			$sql .= 'VALUES (:token)';
			$statement = $bdd->prepare($sql);
			$statement->bindParam(':token', 		$token, 	PDO::PARAM_STR);
			$result = $statement->execute();	
			if($result){
				$json['success'] = 1;									
			}else{
				$json['success'] = 0;
			}				
		}catch(PDOException  $e ){
			echo $e->getMessage( );
			die();
		}
		return $json;
	}
	
	public function getRegisteredToken($bdd){		
		$query = "select * from firebase order by id desc limit 1";
		$statement = $bdd->prepare($query);
		$statement->execute();
		$row=$statement->fetch(PDO::FETCH_ASSOC);
		$token = $row[token];
		return $token;
	}	
}
?>