正在显示
1 个修改的文件
包含
16 行增加
和
4 行删除
@@ -42,10 +42,22 @@ class Db { | @@ -42,10 +42,22 @@ class Db { | ||
42 | return $this->client; | 42 | return $this->client; |
43 | } | 43 | } |
44 | 44 | ||
45 | + private $host=''; | ||
46 | + private $prot=3306; | ||
47 | + private $user=''; | ||
48 | + private $pwd=''; | ||
49 | + private $database=''; | ||
45 | 50 | ||
46 | - public function __construct() | 51 | + |
52 | + public function __construct($host='',$database='',$user='',$pwd='',$prot=3306) | ||
47 | { | 53 | { |
48 | 54 | ||
55 | + $this->host = $host ? $host : DB_HOST; | ||
56 | + $this->prot = $prot ? $prot : DB_PORT; | ||
57 | + $this->user = $user ? $user : DB_USER; | ||
58 | + $this->pwd = $pwd ? $pwd : DB_PASSWORD; | ||
59 | + $this->database = $database ? $database : DB_DATABASE; | ||
60 | + | ||
49 | // $this->connect(); | 61 | // $this->connect(); |
50 | 62 | ||
51 | } | 63 | } |
@@ -62,9 +74,9 @@ class Db { | @@ -62,9 +74,9 @@ class Db { | ||
62 | DBPOOLCONNECTFOR: | 74 | DBPOOLCONNECTFOR: |
63 | try { | 75 | try { |
64 | $this->client = new \PDO( | 76 | $this->client = new \PDO( |
65 | - 'mysql:charset=utf8mb4;dbname='.DB_DATABASE.';host='.DB_HOST.';port='.DB_PORT, | ||
66 | - DB_USER, | ||
67 | - DB_PASSWORD, | 77 | + 'mysql:charset=utf8mb4;dbname='.$this->database.';host='.$this->host.';port='.$this->prot, |
78 | + $this->user, | ||
79 | + $this->pwd, | ||
68 | [ | 80 | [ |
69 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, | 81 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, |
70 | \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'", | 82 | \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'", |
-
请 注册 或 登录 后发表评论