-
Notifications
You must be signed in to change notification settings - Fork 0
/
Db.php
62 lines (58 loc) · 1.59 KB
/
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
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
55
56
57
58
59
60
61
62
<?php
//mssqls数据库连接
//作者:明天见 微信wapele
class Db{
private $conn=null;
private $config=[
"host"=>"127.0.0.10",
"info"=>["UID"=>"sa","PWD"=>"password","Database"=>"Database"]
];
function __construct($config=[]) {
if ($this->config){
$this->config=array_merge($this->config,$config);
}
$this->conn = sqlsrv_connect($this->config["host"],$this->config["info"]);
if (!$this->conn){$this->error();}
}
function execute($sql="",$pre=[]){
$sql= sqlsrv_prepare($this->conn, $sql, $pre);
if (!$sql){$this->error();}
if (sqlsrv_execute($sql)){return 1;}
else{ $this->error(); }
}
function query($sql){
$result = sqlsrv_query($this->conn, $sql);
}
function getRow($sql){
$result = sqlsrv_query($this->conn, $sql);
return sqlsrv_fetch_array($result);
$arr = array();
while($row = sqlsrv_fetch_array($result))
{
$arr[] = $row;
}
return $arr[0];
}
function getAll($sql){
$result = sqlsrv_query($this->conn, $sql);
$arr = array();
while($row = sqlsrv_fetch_array($result))
{
$arr[] = $row;
}
return $arr;
}
function error(){
$error=sqlsrv_errors();
if ($error){
$msg=iconv("gbk", "utf-8//ignore", @$error[0]["message"]);
die($msg);
}
}
function close(){
sqlsrv_close($this->conn);
}
function __destruct() {
unset($this->conn);
}
}