-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_worker.php
49 lines (41 loc) · 1.4 KB
/
db_worker.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
<?php
//must have module
require_once "config.php";
//extends modules
require_once "dbWorkers/inserts.php";
require_once "dbWorkers/updates.php";
require_once "dbWorkers/selects.php";
//mixed functions
function createTable($table){
$sqlDropText = sprintf('DROP TABLE IF EXISTS %s;', $table['name']);
$sqlCreateText = sprintf('CREATE TABLE %s(', $table['name']);
$tmp_cnt = 0;
foreach ($table['fields'] as $field){
if($tmp_cnt===count($table['fields'])-1){
$sqlCreateText = sprintf("%s %s %s %s ", $sqlCreateText, $field['name'], $field['type'], $field['params']);
} else{
$sqlCreateText = sprintf("%s %s %s %s, ", $sqlCreateText, $field['name'], $field['type'], $field['params']);
}
}
$sqlCreateText = sprintf('%s) %s ', $sqlCreateText, CHAR_SET);
}
function deleteRecord($filter ){
$query = sprintf(
"DELETE FROM %s WHERE %s = '%s' ", $filter['tableName'], $filter['key'], $filter['val']);
$rezult = mysqli_query($GLOBALS['CONNECTION'], $query);
if(!$rezult ){
echo '<br>on deleteRecord<br>';
var_dump(mysqli_error($GLOBALS['CONNECTION']));
return false;
}
return true;
}
function deleteContract($contract_id){
$filter = [
'tableName' => 'conn_contracts',
'key' => 'id',
'val' => $contract_id,
];
return deleteRecord($filter);
}
?>