-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmysql.php
More file actions
54 lines (50 loc) · 1.66 KB
/
mysql.php
File metadata and controls
54 lines (50 loc) · 1.66 KB
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
51
52
53
54
<?php
class Mysql{
private static $host="localhost";
private static $user="root";
private static $password="root";
private static $dbName="webdb"; //数据库名
private static $charset="utf8"; //字符编码
private static $port="3306"; //端口号
private $conn=null;
function __construct(){
$this->conn=new mysqli(self::$host,self::$user,self::$password,self::$dbName,self::$port);
if(!$this->conn)
{
die("数据库连接失败!".$this->conn->connect_error);
}else{
echo "";
}
$this->conn->query("set names ".self::$charset);
}
//执行sql语句
function sql($sql){
$res=$this->conn->query($sql);
if(!$res)
{
echo "数据操作失败";
}
else
{
if($this->conn->affected_rows>0)
{
return $res;
}
else
{
echo "0行数据受影响!";
}
}
}
//返回受影响数据行数
function getResultNum($sql){
$res=$this->conn->query($sql);
return mysqli_num_rows($res);
}
//关闭数据库
public function close()
{
@mysqli_close($this->conn);
}
}
?>