changed from PDO to DatabaseConnection

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-22 18:43:51 +01:00
parent 9287ea22db
commit f01efa342f
1 changed files with 12 additions and 12 deletions

View File

@ -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();