Skip to content

Commit

Permalink
Update Table.php
Browse files Browse the repository at this point in the history
  • Loading branch information
secure73 authored Jan 4, 2024
1 parent f770924 commit 42d550a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/core/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,30 @@ public function setTable(): string
{
return '';
}

/**
* @param int $id
* @return null|$this
* if found, set item values to this object and return this object
*/
public function single(int $id):null|object
{
$res = $this->selectQuery("SELECT * FROM {$this->setTable()} WHERE id = :id LIMIT 1",[':id'=>$id]);
if($res === false)
{
$this->setError('Failed to select row from table:'.$this->getError());
return null;
}
if(count($res) == 0)
{
$this->setError('No row found with id:'.$id);
return null;
}
$res = $res[0];
/*@phpstan-ignore-next-line*/
foreach ($res as $key => $value) {
$this->$key = $value;
}
return $this;
}
}

0 comments on commit 42d550a

Please sign in to comment.