-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcmysql.php
133 lines (130 loc) · 3.45 KB
/
pcmysql.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
use function PHPSTORM_META\type;
class pcmysql{
function __construct($host,$user,$pawd=''){
$this->host=$host;
$this->user=$user;
$this->pawd=$pawd;
$this->result = mysqli_connect($this->host,$this->user,$this->pawd);
}
function query($sql){
return mysqli_query($this->result,$sql);
}
function usedata($databasename){
$sql='use '.$databasename;
return $this->query($sql);
}
function getall($tablename){
$sql='select * from '.$tablename;
return $this->query($sql);
}
function perdata($tablename,$nownum=1,$pernum=5){
$sql="select * from ".$tablename." limit ".(($nownum-1)*$pernum). ",".$pernum;
return $this->query($sql);
}
function fdata($tablename,$filed,$filter){
$sql='select * from '.$tablename.' where '.$filed."='".$filter."'";
return $this->query($sql);
}
function delete($tablename,$filed,$filter){
$sql='delete from '.$tablename." where ".$filed."='".$filter."'";
return $this->query($sql);
}
function insert($tablename,$dict){
foreach($dict as $key=>$value){
$keys[]=$key;
$values[]=$value;
}
$field=implode(",",$keys);
$valuesl=implode("','",$values);
$sql = 'insert into '.$tablename."(".$field.")"." value('".$valuesl."')";
$this->query($sql);
}
function updata($tablename,$dict,$find){
foreach($find as $key=>$value){
$fkey=$key;
$fvalue=$value;
}
$str='';
foreach($dict as $key=>$value){
if(gettype($value)=='string'){
$str.=$key."='".$value."',";
}else{
$str.=$key."=".$value.",";
}
}
$str=substr($str,0,strlen($str)-1);
$ftype=gettype($fvalue);
if ($ftype=='string'){
$sql='update '.$tablename." set ".$str." where ".$fkey."='".$fvalue."'";
$this->query($sql);
}else{
$sql='update '.$tablename." set ".$str." where ".$fkey."=".$fvalue;
$this->query($sql);
}
}
function dfdata($tablename,$filter,$logical='and'){
$str='';
foreach($filter as $key=>$value){
if(gettype($value)=='string'){
$str.=$key."='".$value."' ".$logical." ";
}else{
$str.=$key."=".$value." ".$logical." ";
}
}
$str=substr($str,0,strlen($str)-4);
$sql='select * from '.$tablename." where ".$str;
var_dump($sql);
return $this->query($sql);
}
function logical($tablename,$filter,$logic){
foreach($filter as $key=>$value){
$fkey=$key;
$fvalue=$value;
}
$ftype=gettype($value);
if ($ftype=='string'){
$sql='select * from '.$tablename." where ".$fkey.$logic."'".$fvalue."'";
return $this->query($sql);
}else{
$sql='select * from '.$tablename." where ".$fkey.$logic.$fvalue;
return $this->query($sql);
}
}
function specifice($tablename,$field){
$fieds=implode(",",$field);
$sql='select '.$fieds.' from '.$tablename;
return $this->query($sql);
}
function effectnum(){
return mysqli_affected_rows($this->result);
}
function allupdata($tablename,$arr,$find){
$sql='desc '.$tablename;
$fields=$this->query('desc '.$tablename);
foreach($fields as $value){
$arrfields[]=$value['Field'];
}
$str='';
for($i=0;$i<sizeof($arrfields);$i++){
$type=gettype($arr[$i]);
if($type=='string'){
$str.=$arrfields[$i]."='".$arr[$i]."',";
}else{
$str.=$arrfields[$i]."=".$arr[$i].",";
}
}
$str=substr($str,0,strlen($str)-1);
foreach($find as $key=>$value){
$fkey=$key;
$fvalue=$value;
}
if(gettype($fvalue)=='string'){
$sql='update '.$tablename." set ".$str." where ".$fkey."='".$fvalue."'";
}else{
$sql='update '.$tablename." set ".$str." where ".$fkey."=".$fvalue;
}
return $this->query($sql);
}
}
?>