-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
41 lines (35 loc) · 1.02 KB
/
query.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
<?php
function sqlSelect($conn, $columns, $table, $condition)
{
$sql = "SELECT " . $columns . " FROM `" . $table . "` WHERE " . $condition;
$result = $conn->query($sql);
return $result;
}
function sqlInsert($conn, $table, $data)
{
$cols = [];
$values = [];
foreach ($data as $key => $elemnt) {
array_push($cols, $key);
array_push($values, "'" . $elemnt . "'");
};
$sql = "INSERT INTO `" . $table . "` (" . implode(",",$cols) . ") VALUES (" . implode(",",$values) . ")";
$result = $conn->query($sql);
return $result;
}
function sqlUpdate($conn, $table, $data, $id)
{
$setColumn = array();
foreach ($data as $key => $value) {
$setColumn[] = "`{$key}` = '{$value}'";
}
$sql = "UPDATE {$table} SET " . implode(', ', $setColumn) . " WHERE $id";
$result = $conn->query($sql);
return $result;
}
function sqlDelete($conn, $table, $msv)
{
$sql = "DELETE FROM $table WHERE `ma_sinhvien` = '$msv'";
$result = $conn->query($sql);
return $result;
}