I joined this 2 tables and dropped the user_id afterwards. I am defining the user_id elsewhere in my code based on my session/cookies and I do not want to return this value as a global. Is there a more compact or elegant way to write this:
public function test($user_id)
{
$stmt = $this->conn->prepare("CREATE TEMPORARY TABLE `temp_tb`
SELECT a.*, b.token
FROM $this->tableName a
LEFT JOIN `requests` b
ON a.$this->user_id = b.uid
WHERE $this->user_id=:user_id ");
$stmt->execute(array(":user_id"=>$user_id));
$stmt = $this->conn->prepare("ALTER TABLE `temp_tb` DROP $this->user_id ");
$stmt->execute();
$stmt = $this->conn->prepare("SELECT * FROM `temp_tb` ");
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
Thank you!