改进数据库连接的问题

This commit is contained in:
thinkphp
2016-04-27 15:44:50 +08:00
parent 6915f0249e
commit 00cd2e61d9
3 changed files with 6 additions and 4 deletions

View File

@@ -11,7 +11,9 @@
namespace think; namespace think;
use think\Config;
use think\exception\ErrorException; use think\exception\ErrorException;
use think\Log;
class Error class Error
{ {

View File

@@ -23,7 +23,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 数据库对象池 // 数据库对象池
private static $links = []; private static $links = [];
// 数据库配置 // 数据库配置
protected static $connection; protected static $connection = [];
// 数据表名称 // 数据表名称
protected static $table; protected static $table;
// 回调事件 // 回调事件

View File

@@ -98,7 +98,7 @@ abstract class Connection
* @access public * @access public
* @param array $config 数据库配置数组 * @param array $config 数据库配置数组
*/ */
public function __construct($config = '') public function __construct(array $config = [])
{ {
if (!empty($config)) { if (!empty($config)) {
$this->config = array_merge($this->config, $config); $this->config = array_merge($this->config, $config);
@@ -170,12 +170,12 @@ abstract class Connection
/** /**
* 连接数据库方法 * 连接数据库方法
* @access public * @access public
* @param mixed $config 连接参数 * @param array $config 连接参数
* @param integer $linkNum 连接序号 * @param integer $linkNum 连接序号
* @param false|array $autoConnection 是否自动连接主数据库(用于分布式) * @param false|array $autoConnection 是否自动连接主数据库(用于分布式)
* @return \PDO * @return \PDO
*/ */
public function connect($config = '', $linkNum = 0, $autoConnection = false) public function connect(array $config = [], $linkNum = 0, $autoConnection = false)
{ {
if (!isset($this->links[$linkNum])) { if (!isset($this->links[$linkNum])) {
if (!empty($config)) { if (!empty($config)) {