Skip to content

Commit e0d2b9d

Browse files
committed
fix bug when operator not already in table
1 parent 90129fe commit e0d2b9d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

resources/lib/UnitySQL.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ public function addLog(string $action_type, string $recipient): void
157157

158158
public function updateUserLastLogin(string $uid): void
159159
{
160-
$stmt = $this->conn->prepare(
161-
sprintf(
162-
"UPDATE %s SET last_login=CURRENT_TIMESTAMP WHERE operator=:uid",
163-
self::TABLE_USER_LAST_LOGINS,
164-
),
165-
);
160+
$table = self::TABLE_USER_LAST_LOGINS;
161+
$stmt = $this->conn->prepare("
162+
INSERT INTO $table
163+
(operator, last_login)
164+
VALUES(:uid, CURRENT_TIMESTAMP)
165+
ON DUPLICATE KEY UPDATE
166+
last_login=CURRENT_TIMESTAMP
167+
");
166168
$stmt->bindParam(":uid", $uid);
167169
$stmt->execute();
168170
}

0 commit comments

Comments
 (0)