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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
<? class DBCAR { var $db_hostcar; var $db_namecar; var $db_usercar; var $db_passcar; var $debug_modecar; function DBCAR($db_hostcar,$db_namecar,$db_usercar,$db_passcar,$debug_modecar='1') { $this->db_hostcar = $db_hostcar; $this->db_namecar = $db_namecar; $this->db_usercar = $db_usercar; $this->db_passcar = $db_passcar; $this->debug_modecar = $debug_modecar; $this->connectcar = @mysql_connect($this->db_hostcar,$this->db_usercar,$this->db_passcar); @mysql_select_db($this->db_namecar,$this->connectcar); } #테이블을 삭제 function dropTable($table_name) { $qry = 'drop table '.$table_name; return $result = $this->query($qry); } #쿼리만 날리면 되는 함수 function queryRow($qry) { if($this->debug_mode) $result = mysql_query($qry,$this->connect) or die($qry.'<br>'.mysql_errno().' : '.mysql_error()); else $result = @mysql_query($qry,$this->connect) or die('Error'); $row = mysql_fetch_array($result); return $row; } #쿼리만 날리면 되는 함수 function query($qry) { function query($qry) { if($this->debug_mode) $result = mysql_query($qry,$this->connect) or die($qry.'<br>'.mysql_errno().' : '.mysql_error()); else $result = @mysql_query($qry,$this->connect) or die('Error'); $result = $mysql_query($qry,$this->connect); } if($this->debug_mode) $result = mysql_query($qry,$this->connect) or die($qry.'<br>'.mysql_errno().' : '.mysql_error()); else $result = @mysql_query($qry,$this->connect) or die('Error'); return $result; } #쿼리만 날리면 되는 함수 function queryCnt($qry) { if($this->debug_mode) $result['result'] = mysql_query($qry,$this->connect) or die($qry.'<br>'.mysql_errno().' : '.mysql_error()); else $result['result'] = @mysql_query($qry,$this->connect) or die('Error'); $result['cnt'] = mysql_affected_rows(); return $result; } #쿼리만 날리면 되는 함수 function queryIdx($qry) { if($this->debug_mode) $result['result'] = mysql_query($qry,$this->connect) or die($qry.'<br>'.mysql_errno().' : '.mysql_error()); else $result['result'] = @mysql_query($qry,$this->connect) or die('Error'); $result['idx'] = mysql_insert_id(); return $result; } #쿼리에 해당하는 줄수는 넘겨주는 함수 function cnt($table_name,$where="",$fields="count(*)") { $qry = 'select '.$fields.' from '.$table_name.' '.$where; $result = $this->query($qry); $row = mysql_fetch_row($result); if(empty($row['0'])) return 0; return $row['0']; } #셀렉트함수 function select($table_name,$where="",$fields="*") { $qry = 'select '.$fields.' from '.$table_name.' '.$where; return $result = $this->query($qry); } #셀렉트함수 function selectCnt($table_name,$where="",$fields="*") { $qry = 'select '.$fields.' from '.$table_name.' '.$where; return $result = $this->queryCnt($qry); } #데이터 한개만 가지고 오는 함수 function selectOne($table_name,$where="",$fields) { $qry = 'select '.$fields.' from '.$table_name.' '.$where; $result = $this->query($qry); $row = mysql_fetch_row($result); return $row['0']; } #레코드 한개만 가지고 오는 함수 function row($table_name,$where="",$fields="*") { $qry = 'select '.$fields.' from '.$table_name.' '.$where.' limit 1'; $result = $this->query($qry); $row = mysql_fetch_array($result); return $row; } #삭제하는 함수 function del($table_name,$where="") { $qry = 'delete from '.$table_name.' '.$where; return $result = $this->query($qry); } #인서트 함수 첫번째꺼 function insert($table_name,$val) { $qry='insert into '.$table_name.' values ('.$val.')'; return $result = $this->query($qry); } #인서트 set 함수 function insertSet($table_name,$val) { $qry='insert into '.$table_name.' set '.$val; return $result = $this->query($qry); } #인서트 set 함수(auto_increment.값을 가지고 온다.) function insertIdx($table_name,$val) { $qry='insert into '.$table_name.' set '.$val; return $result = $this->queryIdx($qry); } #업데이트함수 function update($table_name, $fields, $where ) { $qry='update '.$table_name.' set '.$fields.' '.$where; return $result = $this->query($qry); } #합계함수 function sum($table_name,$where="",$fields) { $qry = 'select sum('.$fields.') from '.$table_name.' '.$where; $result = $this->query($qry); $row = mysql_fetch_row($result); if(empty($row['0'])) return 0; return $row['0']; } #테이블이 있나 없나 조사하는 함수 function isTable($table_name) { $ret_value = FALSE; $result = mysql_list_tables($this->db_name,$this->connect); while($row = mysql_fetch_row($result)) { if($table_name == $row['0']) { $ret_value = TRUE; break; } } return $ret_value; } // 메세지 출력후 이동하는 자바스크립트 function alertJavaGo($msg,$url) { echo "<script language='javascript'> alert('$msg'); location.replace('$url'); </script>"; exit(); } } ?>
|