prepare($query); $statement->bindValue(":type_id", $type_id); $statement->execute(); $devices = $statement->fetchAll(); $statement->closeCursor(); return $devices; } catch (PDOException $e) { $errorMessage = $e->getMessage(); include('../View/database_error.php'); } } function get_device($device_id) { global $db; $query = 'SELECT * FROM devices WHERE deviceID = :device_id'; try { $statement = $db->prepare($query); $statement->bindValue(":device_id", $device_id); $statement->execute(); $device = $statement->fetch(); $statement->closeCursor(); return $device; } catch (PDOException $e) { $errorMessage = $e->getMessage(); include('../View/database_error.php'); } } function add_device($number, $type_id, $description, $manufacturer_id, $image) { global $db; $query = 'INSERT INTO devices(number, typeID, description, manufacturerID, image) VALUES(:number, :type_id, :description, :manufacturer_id, :image)'; try { $statement = $db->prepare($query); $statement->bindValue(':number', $number); $statement->bindValue(':type_id', $type_id); $statement->bindValue(':description', $description); $statement->bindValue(':manufacturer_id', $manufacturer_id); $statement->bindValue(':image', $image); $statement->execute(); $statement->closeCursor(); } catch (PDOException $e) { $errorMessage = $e->getMessage(); include('../View/database_error.php'); } } function delete_device($device_id) { global $db; $query = 'DELETE FROM devices WHERE deviceID = :device_id'; try { $statement = $db->prepare($query); $statement->bindValue(':device_id', $device_id); $statement->execute(); $statement->closeCursor(); } catch (PDOException $e) { $errorMessage = $e->getMessage(); include('../View/database_error.php'); } } function update_device($device_id, $number, $type_id, $description, $manufacturer_id, $image) { global $db; $query = "UPDATE devices SET number = :number, typeID = :type_id, description = :description, manufacturerID = :manufacturer_id, image = :image WHERE deviceID = :device_id"; try { $statement = $db->prepare($query); $statement->bindValue(':device_id', $device_id); $statement->bindValue(':number', $number); $statement->bindValue(':type_id', $type_id); $statement->bindValue(':description', $description); $statement->bindValue(':manufacturer_id', $manufacturer_id); $statement->bindValue(':image', $image); $statement->execute(); $statement->closeCursor(); } catch (PDOException $e) { $errorMessage = $e->getMessage(); include('../View/database_error.php'); } } ?>