From f01efa342fe9f65b62697dd70395c47b66248ed0 Mon Sep 17 00:00:00 2001 From: tracer Date: Sat, 22 Jan 2022 18:43:51 +0100 Subject: [PATCH] changed from PDO to DatabaseConnection Signed-off-by: tracer --- bindAPI/src/Controller/ApiUsers.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bindAPI/src/Controller/ApiUsers.php b/bindAPI/src/Controller/ApiUsers.php index 9d8e937..97bcecd 100644 --- a/bindAPI/src/Controller/ApiUsers.php +++ b/bindAPI/src/Controller/ApiUsers.php @@ -11,7 +11,7 @@ use PDOException; */ class ApiUsers { - public function __construct(private PDO $dbConnection) + public function __construct(private DatabaseConnection $databaseConnection) {} @@ -22,10 +22,10 @@ class ApiUsers { $sql = " SELECT id, api_token_prefix, api_token - FROM user"; + FROM " . DatabaseConnection::TABLE_USER; try { - $statement = $this->dbConnection->query($sql); + $statement = $this->databaseConnection->getConnection()->query($sql); return $statement->fetchAll(mode: PDO::FETCH_ASSOC); } catch (PDOException $e) { exit($e->getMessage()); @@ -42,12 +42,12 @@ class ApiUsers { $sql = " SELECT api_token_prefix, api_token - FROM user + FROM " . DatabaseConnection::TABLE_USER . " WHERE id = :id; "; try { - $statement = $this->dbConnection->prepare($sql); + $statement = $this->databaseConnection->getConnection()->prepare($sql); $statement->bindParam(param: ':id', var: $id); $statement->execute(); return $statement->fetch(mode: PDO::FETCH_ASSOC); @@ -66,11 +66,11 @@ class ApiUsers { $sql = " SELECT api_token - FROM user + FROM " . DatabaseConnection::TABLE_USER . " WHERE api_token_prefix = :prefix"; try { - $statement = $this->dbConnection->prepare($sql); + $statement = $this->databaseConnection->getConnection()->prepare($sql); $statement->bindParam(param: ':prefix', var: $prefix); $statement->execute(); return $statement->fetch(mode: PDO::FETCH_ASSOC); @@ -97,15 +97,15 @@ class ApiUsers $token = password_hash(password: $tokenPrefix . '.' . $key, algo: PASSWORD_ARGON2ID); $sql = " - INSERT INTO user (api_token_prefix, api_token) + INSERT INTO " . DatabaseConnection::TABLE_USER . " (api_token_prefix, api_token) VALUES (:token_prefix, :token)"; try { - $statement = $this->dbConnection->prepare($sql); + $statement = $this->databaseConnection->getConnection()->prepare($sql); $statement->bindParam(param: ':token_prefix', var: $tokenPrefix); $statement->bindParam(param: ':token', var: $token); $statement->execute(); - $result['row'] = $this->dbConnection->lastInsertId(); + $result['row'] = $this->databaseConnection->getConnection()->lastInsertId(); return $result; } catch (PDOException $e) { exit($e->getMessage()); @@ -121,11 +121,11 @@ class ApiUsers public function delete($id): int { $sql = " - DELETE FROM user + DELETE FROM " . DatabaseConnection::TABLE_USER . " WHERE id = :id"; try { - $statement = $this->dbConnection->prepare($sql); + $statement = $this->databaseConnection->getConnection()->prepare($sql); $statement->bindParam(param: 'id', var: $id); $statement->execute(); return $statement->rowCount();