-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMysql.php
50 lines (44 loc) · 1.19 KB
/
Mysql.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
class Mysql
{
/**
* @var PDO
*/
private $conn;
public function __construct()
{
$host = '127.0.0.1';
$database = 'redisTest';
$username = 'root';
$password = 'dyjh123456';
$this->conn = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$this->conn->exec("set names 'utf8'");
}
public function getConnection()
{
return $this->conn;
}
public function run_select($sql)
{
$stmt = $this->conn->prepare($sql);
$rs = $stmt->execute();
//print_r($rs);
if ($rs) {
// PDO::FETCH_ASSOC 关联数组形式
// PDO::FETCH_NUM 数字索引数组形式
// while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// //print_r($row);die;
// }
//print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} else {
return false;
}
}
public function run_edit($sql)
{
$stmt = $this->conn->prepare($sql);
$stmt->execute();
return $stmt->rowCount();
}
}