multi connections system
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user