-
Notifications
You must be signed in to change notification settings - Fork 0
/
connet_db.php
30 lines (29 loc) · 998 Bytes
/
connet_db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
class DB {
public $ip = 'localhost';
public $root = 'root';
public $password = '';
public $db = 'numberone';
public $port = '3306';
public function fetch($sql, $type="bool") {
$coon = new Mysqli($this->ip, $this->root, $this->password, $this->db, $this->port);
// 设置字符集
$coon->query("SET CHARACTER SET 'utf8'");//读库
$coon->query("SET NAMES 'utf8'");//写库
// 执行sql语句
$result = $coon -> query($sql);
switch($type) {
case "bool":
return $result;
case "object":
return $result -> fetch_object();
case "all":
$arr = array();
while($row = $result -> fetch_assoc()) {
array_push($arr, $row);
}
return $arr;
}
}
}
?>