-
Notifications
You must be signed in to change notification settings - Fork 1
/
quicksql.php
32 lines (32 loc) · 1.11 KB
/
quicksql.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
<?php
class QSql {
public static function insert($tableName, $keysOrkeyValues,$values=null) {
if (is_null($values)) {
return join(" ",[
"INSERT INTO $tableName (",
join(',',array_keys($keysOrkeyValues)),
") VALUES (",
join(',',array_map(function($v){return "'$v'";},array_values($keysOrkeyValues))),
");"
]);
}
return join(" ",[
"INSERT INTO $tableName (",
join(',',array_values($keysOrkeyValues)),
") VALUES",
join(',',array_map(function($v){return "(".join(',',array_map(function($v){return "'$v'";},$v)).")";},$values))
]).";";
}
public static function update($tableName, $keyValues,$where) {
$set=[];
foreach ($keyValues as $key=>$value) $set[]="$key='$value'";
return join(" ",[
"UPDATE $tableName SET",
join(",",$set),
"WHERE ".$where.";"
]);
}
public static function delete($tableName,$where) {
return "DELETE FROM $tableName WHERE $where;";
}
}