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

@@ -4,22 +4,24 @@ namespace Kletellier\PdoWrapper;
class QueryBuilder
{
protected Db $db;
protected ?Db $db;
protected array $columns;
protected array $wheres;
protected array $orders;
protected array $groupby;
protected string $table;
protected string $connection;
protected string $pk;
protected ?int $take;
protected ?int $offset;
protected string $raw_query;
public function __construct($table, $pk = "id")
public function __construct($table, $pk = "id", $connection = "default")
{
$this->table = $table;
$this->pk = $pk;
$this->db = Db::getInstance();
$this->connection = $connection;
$this->db = null;
$this->reset();
}
@@ -175,6 +177,7 @@ class QueryBuilder
private function getData(): mixed
{
$this->db = Db::getInstance($this->connection);
return $this->db->getSelectQuery($this->getQuery());
}
@@ -265,4 +268,14 @@ class QueryBuilder
return $this->getConstructedQuery();
}
}
public function getConnection()
{
return $this->connection;
}
public function setConnection($connection)
{
$this->connection = $connection;
return $this;
}
}