ARTICLE AD BOX
So this is the connection file. This is what we are using but my classmate said its not the best and not the safest but i want to use the structure of it.
<?php function getData($muvelet, $tipus = null, $adat = null) { $db = new mysqli('localhost', 'root', '', 'database'); if ($db->connect_errno != 0) { return $db->connect_error; } if (!is_null($tipus) && !is_null($adat)){ $stmt = $db ->prepare($muvelet); $stmt->bind_param($tipus, ...$adat); $stmt->execute(); $eredmeny = $stmt->get_result(); } else{ $eredmeny = $db->query($muvelet); } if ($db->errno != 0) { return $db->error; } return ($eredmeny->num_rows > 0) ? $eredmeny->fetch_all(MYSQLI_ASSOC) : []; } function editData($muvelet, $tipus = null, $adat = null) { $db = new mysqli('localhost', 'root', '', 'database'); if ($db->connect_errno != 0) { return $db->connect_error; } if (!is_null($tipus) && !is_null($adat)){ $stmt = $db ->prepare($muvelet); $stmt->bind_param($tipus, ...$adat); $stmt->execute(); } else{ $db->query($muvelet); } if ($db->errno != 0) { return $db->error; } return $db->affected_rows > 0 ? true : false; } ?>And also this within the php file:
$metodus = $_SERVER["REQUEST_METHOD"]; $uri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); $uri = explode("/", $uri); $bodyadatok = json_decode(file_get_contents("php://input"), true);