-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.php
292 lines (166 loc) · 3.8 KB
/
blog.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<meta charset="utf-8">
<?php
//todo: continue from search function : no
//todo: add delete function : yes
//todo: add update funtion : yes
//todo: design generateTable function : no
/**
* @param this function main data transfer center
*
*/
function sql($sql,$args = [])
{
try{
$db = new PDO("mysql:host=localhost;dbname=blog","root","");
//sorgumuz $query içine $db ile beraber hazırlanıyor
$query = $db->prepare($sql);
//$query $args ile execute ediliyor
$query->execute($args);
//$collection içine bütün data çekiliyor
$collection = $query->fetchAll(PDO::FETCH_OBJ);
return $collection;
}
catch (PDOexception $e){
print $e->getMessage();
}
}
/**
* @param connect db
*
* */
function connectDb(){
try{
$db = new PDO("mysql:host=localhost;dbname=blog","root","");
//echo "succes";
return $db;
}
catch (PDOexception $e){
print $e->getMessage();
}
}
/**
* @param sent text or data for db
*
* */
function sentData(){
sql('Insert into texttable(head,text,public) Values(?,?,?)',[$head,$text,$public]);
}
/**
* @param get text or data from database
* @param all get data
* */
function getData(){
$data=sql('select * from texttable ');
return $data;
}
/**
* @param search data from uyeler table
*
*
*/
function loginSql(){
//var_dump($_POST);
$userName=$_POST["userName"];
$userPass=$_POST["userPass"];
$data=sql('SELECT * FROM uyeler ');
//AND `admin` = 2
foreach ($data as $key) {
if($userName==$key->userName && $userPass==$key->userPass )
{
return 'true';
}
}
}
/**
* @param data list for view
* @param dont just complete
*
* */
function search(){
//$ara = $db->prepare("SELECT * FROM kullanici_bilgileri WHERE ad LIKE ? LIMIT 10");
//$sqlTest='SELECT * FROM `uyeler` WHERE `userName` LIKE '%userName%' AND `userPass` LIKE '%userPass%' AND `admin` != 2';
//$userName=$_POST['userName'];
//$userPass=$_POST['userPass'];
$userName='adminRoot';
$userPass='root';
//$data=sql('select * from uyeler where userName and userPass like ?',[$userName,$userPass]);
$data=sql("SELECT * FROM 'uyeler' WHERE 'userName' LIKE '?' AND 'userPass' LIKE '?' AND 'admin' = 2",[$userName,$userPass]);
var_dump($data);
}
/**
* @param delete from db
*
* */
function deleteData($i){
sql(" DELETE FROM texttable WHERE id='$i' ");
}
/**
* @param update data from db
* todo: prepare post variable
*/
function updateData($id){
$head="degisti";
sql("UPDATE `texttable` SET `head`='$head' WHERE `id`=$id");
}
/**
* @param create <tr> from view
* @param this function is disable at now
* */
function generateTable($array){
$id=$array['id'];
$head=$array['head'];
$text=$array['text'];
$public=$array['public'];
echo "<br>";
echo "
<tr>
<h4 id='baslik'>$id</h4>
</tr>
<tr>
<p id='metin'>$head alanı</p>
</tr>
<tr>
<p id='metin'>$text alanı</p>
</tr>
<tr>
<p id='metin'>$public alanı</p>
</tr>
";
}
/**
*
*@param count from getting data and convert array
*
*/
function counting(){
$data=getData();
//print_r($data[0]);
$array = (array)$data;
for($i=0;$i<count($data); $i++){
$array = (array)$data[$i];
generateTable($array);
echo "<br>";
}
}
/**
* @param tester functions
*
*/
/*$head='deneme2';
$text='asdmalsdmİPFNLSDNFALŞNDLŞANDFMİSAMŞMDSŞAFSM0';
$public=1;
//test functions
//connectDb();
$head='deneme3500';
$text='textmetin';
$public='6631';
sentData($head,$text,$public);
$data = sql('Select * from texttable');
var_dump($data);
*/
//generateTable();
//counting();
//search();
//deleteData();
//updateData(1);
?>