- <?php
-
- namespace Kernel\Classes;
-
- class DB {
- protected $connect_instance;
- protected $db_config;
-
- public function __construct(Array $db_config) {
- $this -> db_config = $db_config;
- }
-
- public function connecting() {
- $this -> connect_instance = new \mysqli(
- $this -> db_config["host"],
- $this -> db_config["user"],
- $this -> db_config["password"],
- $this -> db_config["name"]
- );
-
- if ($this -> connect_instance -> connect_error) {
- throw new \Exception("Ошибка подключения: " . $this -> connect_instance -> connect_error);
- }
- }
-
- public function query(String $sql) {
- if(!$this -> connect_instance) {
- $this -> connecting();
- }
-
- return $this -> connect_instance -> query($sql);
- }
-
- public function last_insert_id() {
- return $this -> connect_instance -> insert_id;
- }
- }