changed from PDO to DatabaseConnection
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
9287ea22db
commit
f01efa342f
|
@ -11,7 +11,7 @@ use PDOException;
|
||||||
*/
|
*/
|
||||||
class ApiUsers
|
class ApiUsers
|
||||||
{
|
{
|
||||||
public function __construct(private PDO $dbConnection)
|
public function __construct(private DatabaseConnection $databaseConnection)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,10 +22,10 @@ class ApiUsers
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, api_token_prefix, api_token
|
SELECT id, api_token_prefix, api_token
|
||||||
FROM user";
|
FROM " . DatabaseConnection::TABLE_USER;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->query($sql);
|
$statement = $this->databaseConnection->getConnection()->query($sql);
|
||||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
|
@ -42,12 +42,12 @@ class ApiUsers
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT api_token_prefix, api_token
|
SELECT api_token_prefix, api_token
|
||||||
FROM user
|
FROM " . DatabaseConnection::TABLE_USER . "
|
||||||
WHERE id = :id;
|
WHERE id = :id;
|
||||||
";
|
";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':id', var: $id);
|
$statement->bindParam(param: ':id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||||
|
@ -66,11 +66,11 @@ class ApiUsers
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT api_token
|
SELECT api_token
|
||||||
FROM user
|
FROM " . DatabaseConnection::TABLE_USER . "
|
||||||
WHERE api_token_prefix = :prefix";
|
WHERE api_token_prefix = :prefix";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':prefix', var: $prefix);
|
$statement->bindParam(param: ':prefix', var: $prefix);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||||
|
@ -97,15 +97,15 @@ class ApiUsers
|
||||||
$token = password_hash(password: $tokenPrefix . '.' . $key, algo: PASSWORD_ARGON2ID);
|
$token = password_hash(password: $tokenPrefix . '.' . $key, algo: PASSWORD_ARGON2ID);
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
INSERT INTO user (api_token_prefix, api_token)
|
INSERT INTO " . DatabaseConnection::TABLE_USER . " (api_token_prefix, api_token)
|
||||||
VALUES (:token_prefix, :token)";
|
VALUES (:token_prefix, :token)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
||||||
$statement->bindParam(param: ':token', var: $token);
|
$statement->bindParam(param: ':token', var: $token);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$result['row'] = $this->dbConnection->lastInsertId();
|
$result['row'] = $this->databaseConnection->getConnection()->lastInsertId();
|
||||||
return $result;
|
return $result;
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
|
@ -121,11 +121,11 @@ class ApiUsers
|
||||||
public function delete($id): int
|
public function delete($id): int
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
DELETE FROM user
|
DELETE FROM " . DatabaseConnection::TABLE_USER . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
|
|
Loading…
Reference in New Issue