/** * */ protected function buildRelations() { $sql = 'SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `COLUMN_NAME`, `REFERENCED_TABLE_SCHEMA`, `REFERENCED_TABLE_NAME`, `REFERENCED_COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = SCHEMA() AND `REFERENCED_TABLE_NAME` IS NOT NULL;'; $prepare = $this->repository->getConnection()->prepare($sql); $prepare->execute(); foreach ($prepare->fetchAll(PDO::FETCH_ASSOC) as $result) { $table = $result['TABLE_NAME']; $primary = $result['COLUMN_NAME']; $references = $result['REFERENCED_TABLE_NAME']; $on = $result['REFERENCED_COLUMN_NAME']; $key = 'FOREIGN__' . substr($table . '__' . $primary, -55); $this->cache['constraints'][$table][$key] = ['type' => 'FOREIGN', 'primary' => $primary, 'references' => $references, 'on' => $on]; } }
/** * @param $table * @param array $data * * @return mixed * @throws Exception */ public function insert($table, array $data = []) { /** * We will insert $data into $table ... */ $query = (new Insert())->table($table)->setInsert($data); /** * ... prepare query ... */ $prepare = $this->repository->prepareQuery($query); /** * ... execute it ... */ $this->repository->executePrepared($prepare); /** * ... and return inserted ID. */ return $this->repository->getConnection()->lastInsertId(); }