-
Notifications
You must be signed in to change notification settings - Fork 0
/
customfunctionlibrary.php
55 lines (50 loc) · 2.38 KB
/
customfunctionlibrary.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
<?php
function upload_to_db($table,$item,$values){
global $dbserver,$dbusername,$dbpassword,$dbname,$dbport,$dbaccess;
if ($dbaccess == false){
return 'Unable to access database';
}
else{
$gundbcon = new mysqli($dbserver,$dbusername,$dbpassword,$dbname,$dbport);
$uploaddataSQL = "INSERT INTO ".mysqli_real_escape_string($gundbcon,$table)." (".$item.") VALUES (".$values.")";
//$uploaddataSQL = "SELECT ".mysqli_real_escape_string($gundbcon,$item)." FROM ".mysqli_real_escape_string($gundbcon,$table)." WHERE ".mysqli_real_escape_string($gundbcon,$cat)." = '".mysqli_real_escape_string($gundbcon,$id)."';";
//$uploaddataResult = $gundbcon->query($uploaddataSQL);
// Fetch all
if (mysqli_query($gundbcon, $uploaddataSQL)) {
return "New record created successfully";
} else {
return "Error: " . $uploaddataSQL . "---" . mysqli_error($gundbcon);
}
mysqli_close($gundbcon);
}
}
function get_arr_from_db($item,$id,$cat,$table){
global $dbserver,$dbusername,$dbpassword,$dbname,$dbport,$dbaccess;
if ($dbaccess == false){
return 'Unable to access database'.$dbserver.$dbusername.$dbpassword.$dbname.$dbport;
}
else{
$gundbcon = new mysqli($dbserver,$dbusername,$dbpassword,$dbname,$dbport);
$getinfoSQL = "SELECT ".mysqli_real_escape_string($gundbcon,$item)." FROM ".mysqli_real_escape_string($gundbcon,$table)." WHERE ".mysqli_real_escape_string($gundbcon,$cat)." = '".mysqli_real_escape_string($gundbcon,$id)."';";
$getinfoResult = $gundbcon->query($getinfoSQL);
// Fetch all
if ($getinfoResult != ''){
$getinfoarray = mysqli_fetch_all($getinfoResult,MYSQLI_NUM);
if ($getinfoarray != NULL){
mysqli_close($gundbcon);
//return $getinfoarray;
return $getinfoarray;
}
else{
mysqli_close($gundbcon);
return 'No results';
}
}
else{
mysqli_close($gundbcon);
return 'No results';
}
}
}
#-----ENDFUNCTIONLIBRARY-----#
?>