function debug($level = self::DEBUG_ON) { parent::debug($level); if ($this->debugLevel & self::DEBUG_EXPLAIN && $this->isConnected) { $this->pdo->exec('SET TRACE ON'); } }
function debug($enable = true, $loggingResult = true, $loggingExplain = true) { parent::debug($enable = true, $loggingResult = true, $loggingExplain = true); if ($this->loggingExplain && $this->isConnected) { $this->pdo->exec('SET TRACE ON'); } }
function connect() { if ($this->isConnected) { return; } parent::connect(); $serverVersion = $this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION); $this->isMariaDB = strpos($serverVersion, 'MariaDB') !== false; if ($this->isMariaDB) { $this->version = substr($serverVersion, 0, strpos($serverVersion, '-')); } else { $this->version = floatval($serverVersion); } if (!$this->isMariaDB && $this->version >= 5.5) { $this->encoding = 'utf8mb4'; } $this->pdo->setAttribute(\PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES ' . $this->encoding); //on every re-connect $this->pdo->exec('SET NAMES ' . $this->encoding); //also for current connection }
function createQuery($type, $properties, $primaryKey = 'id', $uniqTextKey = 'uniq', $cast = [], $func = []) { if (!$this->foreignKeyEnabled) { $this->enableForeignKeys(); } return parent::createQuery($type, $properties, $primaryKey, $uniqTextKey, $cast, $func); }
function joinCascade($map = []) { $q = $this; $db = $this->dataSource; foreach ($map as $table => $on) { $parent = array_shift($on); if (substr($table, 0, 4) == 'via:') { $table = substr($table, 4); $inversion = true; } else { $inversion = false; } $tableEsc = $this->esc($table); $tablePk = $db[$table]->getPrimaryKey(); $tablePkEsc = $this->esc($tablePk); $parentEsc = $this->esc($parent); $parentPk = $db[$parent]->getPrimaryKey(); $parentPkEsc = $this->esc($parentPk); $parentCol = $parent . '_' . $parentPk; $parentColEsc = $this->esc($parentCol); $tableCol = $table . '_' . $tablePk; $tableColEsc = $this->esc($tableCol); if ($inversion) { $join = "{$tableEsc} ON {$tableEsc}.{$parentColEsc} = {$parentEsc}.{$parentPkEsc}"; } else { $join = "{$tableEsc} ON {$tableEsc}.{$tablePkEsc} = {$parentEsc}.{$tableColEsc}"; } $params = []; foreach ($on as $extra) { if (DataSourceSQL::canBeTreatedAsInt($extra)) { $params[] = $extra; $extra = "{$tableEsc}.{$tablePkEsc} = ?"; } if (is_array($extra)) { $tmp = array_shift($extra); $params[] = $extra; $extra = $tmp; } $join .= " AND {$extra}"; } $q = $q->join($join, $params); } return $q; }