/** * Установка адаптера по умолчанию. */ public static final function setDefaultAdapter($adapter) { self::$def_adapter = $adapter; }
/** * PDO does not appear to have a disconnect function. */ public static function disconnect() { self::$PDO = null; }
/** * Queries the database and returns an iterable DBResult object with * query results. * * You can either provide the SQL query as a string, or as table name, * fields list, conditions (see DB::conditionsToSql() docs for info) and * offset/limit. * * Can only be used for SELECT queries. * * @param string $sql_or_table SQL query or table name * @param mixed $fields Array or string of field names * @param array $conditions Conditions for WHERE * @param string $limit Either limit or offset,limit * @return \Libs\DBResult * @throws DBQueryException */ public static function select($sql_or_table, $fields = null, $conditions = null, $limit = false) { if ($fields) { $fields = self::fieldsToSql($fields); $conditions = $conditions ? ' WHERE ' . self::conditionsToSql($conditions) : ''; $limit = $limit ? " LIMIT {$limit}" : ''; $table = self::quoteField($sql_or_table); $sql = "SELECT {$fields} FROM {$table}{$conditions}{$limit};"; } else { $sql = $sql_or_table; } $query = self::$pdo->prepare($sql); $error = self::error(); if ($error) { $message = "Database query error: ({$error[0]}/{$error[1]}) {$error[2]} in query [{$sql}]"; throw new DBQueryException($message, E_USER_WARNING); return false; } $result = new DBResult($query, self::$fetchMode); self::$lastSQL = (string) $result->query->queryString; $result->callback = function ($sql, $time) { $class = __CLASS__; $class::log($sql, $time); }; return $result; }
/** * Register exception callback * If connection to server fails, exception will be passed to callback as first param * @param \Closure $callback */ public static function registerExceptionCallback($callback) { self::$exception_callback = $callback; }