-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.php
292 lines (218 loc) · 5.56 KB
/
example.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* Created By Furkan
* @author Furkan Çelik
* @web http://www.furkancelik.com.tr
* @email [email protected]
* @date 06 Kasım 2014
*
**/
//Include Class File
include __DIR__."/Connection.Class/Connection.php";
//Creating a database connection
/*
* $DB = Connection::Connect(HOST,DBNAME,Username,Password,DBPort=3306);
*
* */
$DB = Connection::Connect("localhost","deneme","root","");
//Using the Query method
/*
* $DB->Query(SQL,array VALUE=Null);
*
* */
$Query = $DB->Query("SELECT * FROM uye WHERE username=?",array("furkan"));
//Using the error Method
/*
* $DB->error()
*
* Screen prints Sql Code and errors
* */
$DB->error();
//Using the rowCount Method
/*
* $Query->rowCount()
*
* Screen prints total row count
* */
$Query->rowCount();
//Using the fetch and fetchAll method
/*
*
* $DB->fetch(fetch style) or $DB->fetchAll(fetch style)
*
* fetch style = PDO::Fetch Metod or
*
* ASSOC
* BOTH
* BOUND
* INTO
* LAZY
* NUM
* OBJ
*
*
* */
$user = $DB->fetch("OBJ");
echo $user->id;
echo $user->username;
//Using the Insert method
/*
* $DB->Insert(table name)->get(array = null);
* $DB->Insert("table")->get(array(column name => value,column name => value , ... ));
*
* */
$Query = $DB->Insert("uye")->get(array("username"=>"furkan"));
/*
* LastID
*
* */
echo $DB->lastId();
//Using the Update method
/*
* $DB->Update(table name)->Where(column name , value , mark = '=')->get(array = null);
* $DB->Update("table")->Where("id","?")->get(array(column name => value,column name => value , ... , where column value));
*
* if the database column name of the get method if the number is in the key of the array is %3 in the form of use
*
* usersdb:
* |id|username|password|1|
* |1|furkan | ***** |0|
* |2|ahmet | ***** |0|
* |3|simge | ***** |0|
* |4|elif | **** |0|
* |5|hasan | **** |0|
*
* $Query = $DB->Update("usersdb")->Where("id","?,?,?","IN")->get(array("%1"=>5,1,3,4));
*
* updated table
*
* usersdb:
* |id|username|password|1|
* |1|furkan | ***** |5|
* |2|ahmet | ***** |0|
* |3|simge | ***** |5|
* |4|elif | **** |5|
* |5|hasan | **** |0|
*
*
*
* */
$Query = $DB->Update("uye")->Where("id","?","=")->get(array("username"=>"furkan",3));
if ($Query){ echo "success";} else {echo "fail";}
//Using the Delete method
/*
* $DB->Delete(table name)->Where(column name , value , mark = '=')->get(array = null);
* $DB->Delete("table")->Where("id","?")->get(array(value));
*
* */
$Query = $DB->Delete("uye")->Where("id","?","=")->get(array(1));
if ($Query){ echo "success";} else {echo "fail";}
//Using the Select method
/*
* $DB->Select(table name)->get(array = null);
* $DB->Select("table")
* ->From("username,password")
* ->Where("id","?")
* ->orWhere("age","?",">")
* ->andWhere("city","?")
* ->orderBy("id","az") # az , za , ASC , DESC ( az = ASC , za = DESC )
* ->groupBy("age")
* ->Join("tablename","column1","=","column2","INNER")
* ->Limit(0,5)
* ->get();
*
* */
$Query = $DB->Select("uye")
->Where("name","?","LIKE")
->orWhere("age","?",">")
->andWhere("city","?")
->orderBy("id","az") # az , za , ASC , DESC ( az = ASC , za = DESC )
->groupBy("age")
->Join("countrytable","country","=","country","INNER")
->Limit(0,5)->get(array("%a%",20,"Turkey"));
/*
* rowCount
*
* */
echo $DB->rowCount();
// Where the method of use detailed
/*
*
* ...->Where($column,$value,$mark)->...
* $column = the table column
* $value = default value ? ( ? it is recommended that you use the value )
* $mark = default value =
* $mark the values
* LIKE
* IN
* BETWEEN
*
* The where method on your own, you can write
*
* ..->Where("age>'20' and (city='Isparta' and city='Ankara')")->...
*
* orWhere and andWhere methods are not allowed to write
*
* */
// orderBy the method of use detailed
/*
* ..->orderBy($column,$sort)
* $column = the table column
* $sort = az , za , ASC , DESC
*
* */
// groupBy the method of use detailed
/*
* ..->groupBy($column)
* $column = the table column
*
* */
// Join the method of use detailed
/*
* ..->Join($table,$column1,$mark,$column2,$joinType)
* $table= to be merged table
* $column1 = in the first table on any column
* $mark = mark =
* $column2 = in the second table on any column
* $joinType = the default value INNER possible values;
* LEFT
* RIGHT
* FULL OUTER
*
* */
// Limit the method of use detailed
/*
* ..->Limit($start,$last)
* $start = the first value
* $last = the last value
*
* */
// get the method of use detailed
/*
* ..->get(array $values = null)
*
* in this method, a query is run and values set.
*
*
* */
// toSql the method of use detailed
/*
* sql query code creates.
* ..->toSql(array $values = null,$returntype=0)
* $values = query values
* $returntype = two takes value (0 = return sql query, 1 echo sql query )
*
$DB->Select("users")
->From("username,password,city as c")
->Where("id","?,?,?,?,?","IN")
->toSql(array(1,2,3,4,5),1);
*
* screen output
*
* SELECT username,password,city as c FROM users WHERE id IN (?,?,?,?,?)
*
* */
echo $DB->Select("users")
->From("username,password,city as c")
->Where("id","?,?,?,?,?","IN")
->toSql(array(1,2,3,4,5));