Use object oriented

Use object oriented mysql class for db functions
This commit is contained in:
Yiğit Kerem Oktay 2020-08-16 21:44:36 +03:00 committed by GitHub
parent 0825daa570
commit d2c0808f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,40 +3,46 @@
class SSDB
{
function execute($link,$sql){
if ($result = mysqli_query($link, $sql)) {
return true;
function execute($conn,$sql){
if ($conn->query($sql) === TRUE) {
return true;
} else {
die("SQL Failure.Traceback:" . $sql . " Detailed info:" . mysqli_error($link));
}
return $conn->error;
}
function getSetting($link,$setting){
$sql = "SELECT value FROM settings WHERE setting=\"".$setting."\";";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) == 1){
while($row = mysqli_fetch_array($result)){
return $row['value'];
}
}
else{
return "none";
}
}
$conn->close();
}
function setSetting($link,$settingname,$settingvalue){
function getSetting($conn,$setting){
$sql = "SELECT value FROM settings WHERE setting='".$setting."';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
return $row["value"];
}
} else {
return "null";
}
$conn->close();
}
function setSetting($conn,$settingname,$settingvalue){
$sql = "INSERT INTO settings (setting,value) VALUES ('".$settingname."','".$settingvalue."');";
if ($result = mysqli_query($link, $sql)) {
return true;
} else {
die("SQL Failure.Traceback:" . $sql . " Detailed info:" . mysqli_error($link));
}
if ($conn->query($sql) === TRUE) {
return true;
} else {
return $conn->error;
}
$conn->close();
}
function deleteSetting($link,$settingname){
function deleteSetting($conn,$settingname){
$sql = "DELETE FROM settings WHERE setting=\"".$settingname."\";";
if ($result = mysqli_query($link, $sql)) {
return true;
} else {
die("SQL Failure.Traceback:" . $sql . " Detailed info:" . mysqli_error($link));
}
if ($conn->query($sql) === TRUE) {
return true;
} else {
return $conn->error;
}
$conn->close();
}
}