multi connections system

This commit is contained in:
Gregory Letellier
2023-10-30 09:34:16 +01:00
parent 68de5a7d96
commit 47a64d4af0
4 changed files with 94 additions and 24 deletions

View File

@@ -7,13 +7,14 @@ class Model
protected mixed $values;
protected array $updated;
protected string $table;
protected string $connection = "default";
protected string $pk;
private Db $db;
private ?Db $db;
private bool $new;
public function __construct()
{
$this->db = Db::getInstance();
$this->db = null;
$this->new = true;
$this->values = array();
$this->updated = array();
@@ -43,6 +44,17 @@ class Model
return $this;
}
public function getConnection()
{
return $this->connection;
}
public function setConnection($connection)
{
$this->connection = $connection;
return $this;
}
public function fillData(mixed $data): self
{
$this->values = $data;
@@ -53,6 +65,7 @@ class Model
public function save(): bool
{
$this->db = Db::getInstance($this->connection);
$ret = false;
$qb = $this->newQueryBuilder();
if ($this->new) {
@@ -84,7 +97,7 @@ class Model
public function newQueryBuilder(): QueryBuilder
{
return new QueryBuilder($this->table, $this->pk);
return new QueryBuilder($this->table, $this->pk, $this->connection);
}
public function __set($name, $value): void