mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进数据库连接的问题
This commit is contained in:
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
// 回调事件
|
// 回调事件
|
||||||
|
|||||||
@@ -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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user