获取数据库的所有collection
@access public
@param string  $db 数据库名称 留空为当前数据库
@throws Exception
970764
public function listCollections($db = '')
    {
        $cursor = $this->cmd('listCollections', null, $db);
        $result = [];
        foreach ($cursor as $collection) {
            $result[] = $collection['name'];
        }
        return $result;
    }
634964
public function getCollection($db = null)
    {
        if ($db === null) {
            $db = Yii::$app->get('mongodb');
        }

        return $db->getCollection($this->from);
    }
1361195
public static function _genQuery ($params, &$db = FALSE)
	{
		
		// Set select

		if (!isset ($params['select']))
		{
			$params['select']	= '*';
		}
		
		// Set from

		if (!isset ($params['from']))
		{
			$params['from']		= '`' . static::$dbTable . '`';
		}
		
		// Get database slave for read

		if ($db === FALSE)
		{
			$db	=& self::_getDbSlave ();
		}
		
		if (!($db instanceof \PDO))
		{
			throw new Exception ('Invalid or no database resource set');
		}
		
		// Return value

		return $db->genQuery ($params);
		
	}
58656
public function execute($sql) {

        //如果开启了调试模式，那么把所有对数据库写操作的语句记录下来
        if ( SQL_LOG &&
            (strpos($sql, 'INSERT') !== false
                || strpos($sql, 'DELETE') !== false
                || strpos($sql, 'REPLACE') !== false
                    || strpos($sql, 'UPDATE') !== false)) {
            Log::info($sql, 'sql');
        }
        if ( $this->link == null ) $this->connect();
        try {
            $result = $this->link->query($sql);
        } catch ( PDOException $e ) {
            $exception = new DBException("SQL错误:" . $e->getMessage());
            $exception->setCode($e->getCode());
            $exception->setQuery($sql);
            if ( APP_DEBUG ) {
                __print($sql);
            }
            throw $exception;
        }
        return $result;
    }
831254
public function select($index = 0) {

        $index = intval($index);

        if (isset($this->pool['master']) && !is_null($this->pool['master'])) {
            $res = $this->pool['master']->getHandler()->select($index);
            if (!$res) {
                throw new Exception('change selected database failed');
            }
        }

        if (isset($this->pool['slave']) && !is_null($this->pool['slave'])) {
            $res = $this->pool['slave']->getHandler()->select($index);
            if (!$res) {
                throw new Exception('change selected database failed');
            }
        }

        // 记录当前redis db
        $this->currentDb = $index;
    }
1148155
protected function cleanupMongoDB()
    {
        try {
            $this->dbh->drop();
        } catch (\MongoDB\Driver\Exception $e) {
            throw new \Exception(sprintf('Failed to drop the DB: %s', $e->getMessage()));
        }
    }
303969
public static function drop_db($database = null)
	{
		if (empty($database))
		{
			throw new \Mongo_DbException('Failed to drop MongoDB database because name is empty');
		}

		else
		{
			try
			{
				static::instance()->connection->{$database}->drop();
				return true;
			}
			catch (\Exception $e)
			{
				throw new \Mongo_DbException("Unable to drop Mongo database `{$database}`: {$e->getMessage()}", $e->getCode());
			}

		}
	}
1118053
public function getCursor($collection = "")
		{
			if (empty($collection)) {
				throw new Exception("In order to retrieve documents from MongoDB you must provide a collection name.");
			}

			$documents = $this->db->{$collection}
			->find($this->wheres, $this->selects)
			->limit((int) $this->limit)
			->skip((int) $this->offset)
			->sort($this->sorts);

			$this->_clear();

			return $documents;
		}
1278747
final public function rollBack()
    {
        if (!$this->pdo) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        if ($this->_begintransaction) {
            $this->pdo->rollBack();
            $this->_begintransaction = false;
        }
        return $this;
    }
65829
public static function find($collection, $query = null, $fields = array())
  {
    static::checkConnexion();
    $collection = self::$db->$collection;
    if (is_string($query)) {
      $query = json_decode($query, true);
      if (!$query) {
        throw new \Exception('Requête JSON formulée incorrectement');
      }
    }
    if ($query) {
      return $collection->find($query, $fields);
    } else {
      return $collection->find(array(), $fields);
    }
  }
737706
final public function begin()
    {
        if (!$this->pdo) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        if ($this->_begintransaction) {
            throw new Exception("已经开启了一个事务，请勿重新开启", Exception::CODE_DATABASE_ERROR);
        }
        $this->pdo->beginTransaction();
        $this->_begintransaction = true;
        return $this;
    }
330064
public function query($callback, $bindId = null, $sql = null, Context $context = null)
    {
        if ($sql == null) {
            $sql = $this->dbQueryBuilder->getStatement(false);
            $this->dbQueryBuilder->clear();
        }
        if (empty($sql)) {
            throw new Exception('sql empty');
        }
        $data = [
            'sql' => $sql
        ];
        $data['token'] = $this->addTokenCallback($callback);
        if (! empty($bindId)) {
            $data['bind_id'] = $bindId;
        }
        // 写入管道
        $this->asynManager->writePipe($this, $data, $this->workerId);
    }
1366724
protected function useConfiguredDatabase()
    {
        try {
            $this->getDbConnection()->exec('USE `' . $this->getDbName() . '`');
        } catch (Exception $e) {
            throw new Exception("Could not connect to database " . $this->getDbName());
        }
    }
165894
public function connectToDB(){
        //if querybuilder is already connected there is no nedd to connect again
        if($this->queryBuilder->isConnected()) {
            return;
        }
        //check for database parameters
        if(empty($this->DBParameters)) {
            throw new \Exception('missing database parameters');
        }
        $this->queryBuilder->connect(
            $this->DBParameters['driver'],
            $this->DBParameters['host'],
            $this->DBParameters['database'],
            $this->DBParameters['username'],
            $this->DBParameters['password'],
            $this->DBParameters['charset'],
            $this->DBParameters['collation'],
            $this->DBParameters['options']
        );
    }
954758
public function getSQL(): string
    {
        if ($this->query === null) {
            throw new Exception('Query wasn\'t set');
        }

        if (is_object($this->query)) {
            if (method_exists($this->query, '__toString')) {
                return $this->query->__toString();
            }
        } else {
            return trim($this->query);
        }

        $className = get_class($this->query);
        throw new Exception("Can not use class={$className} as database query because it can't be used as string");
    }
892995
public function dumpDB($dumpName = 'test')
    {
        $tables = $this->getDbTables();

        if (empty($tables)) {
            $dbName = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('dbName');
            throw new Exception("no tables on '$dbName'' database");
        }

        $columns = $this->getTableColumns($tables);
        $data = $this->getTableData($tables);
        $checksum = $this->getTableChecksum($tables);

        $this->dbDump[$dumpName] = array('columns' => $columns, 'data' => $data, 'checksum' => $checksum);
    }
827755
public function delUserRole($id)
    {
        if (empty($id)) {
            throw new Exception('参数错误');
        }
        $model = new UserRole($this->db);
        if ($model->where('user_id', $id)->delete() === false) {
            throw new Exception('删除用户角色出错');
        }
        return true;
    }