It's been weeks since I start learning Slim using Zend TableGateway from slim-api-skeleton.
It seems I can't run 2 consecutive query using TableGateway. It's always produce (not just UPDATE):
"Statement couldn't be produced with sql: UPDATE `users` SET `last_access` = NOW() WHERE `id` = ?"
Here's the code inside ZendUserRepository class:
public function __construct(array $config) {
$adapter = new Adapter($config);
$this->table = new TableGateway("users", $adapter);
}
...
public function footprint(int $id): void {
$data = ['last_access' => new Predicate\Expression('NOW()')];
$where = ['id' => $id];
$this->table->update($data, $where);
}
public function authenticate(string $username, string $password): bool {
$where = [
'username' => $username,
new Predicate\IsNotNull('roles')
];
$rowset = $this->table->select($where);
if (null === $row = $rowset->current()) {
return false;
}
$data = (array) $row;
if(password_verify($password, $data['password'])) {
$this->footprint($data['id']);
return true;
}
return false;
}
This frustrate me for days. Since the update function also use 2 consecutive query.
public function update(User $user): void {
$data = $this->hydrator->extract($user);
if (!$this->contains($user)) {
throw new UserNotFoundException;
}
$where = ["id" => $user->getId()];
$this->table->update($data, $where);
}
public function contains(User $user): bool {
try {
$this->get($user->getId());
} catch (UserNotFoundException $exception) {
return false;
}
return true;
}
Thank you.