Skip to content

Commit

Permalink
改进数据库连接配置 支持dsn配置
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Mar 7, 2019
1 parent f84f912 commit 1438072
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ public function connect(array $config = [], $linkNum = 0)
$this->config['pk'] = 'id';
}

$host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
if (empty($config['dsn'])) {
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
}

if ($config['debug']) {
$startTime = microtime(true);
}

$this->links[$linkNum] = new Manager($host, $this->config['params']);
$this->links[$linkNum] = new Manager($config['dsn'], $config['params']);

if ($config['debug']) {
// 记录数据库连接信息
Expand Down Expand Up @@ -829,7 +831,7 @@ public function update(Query $query)
$pk = $query->getPk($options);

if (empty($options['where'])) {
if ($this->getConfig('pk_convert_id') && $pk == '_id') {
if ($this->getConfig('pk_convert_id') && '_id' == $pk) {
$pk = 'id';
}

Expand Down Expand Up @@ -887,7 +889,7 @@ public function update(Query $query)

$query->trigger('after_update');
}

$query->setOption('where', []);

return $result;
Expand Down

0 comments on commit 1438072

Please sign in to comment.