Skip to content
PHP Logo

How can a PHP developer ensure data security and integrity when retrieving and displaying sensitive information like employee schedules from a MySQL database?

To ensure data security and integrity when retrieving and displaying sensitive information like employee schedules from a MySQL database, a PHP developer can implement proper input validation, use parameterized queries to prevent SQL injection attacks, encrypt sensitive data before storing it in the database, and restrict access to the information based on user roles and permissions.

php
<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Retrieve and display employee schedules
$stmt = $conn->prepare("SELECT schedule FROM employee_schedules WHERE employee_id = ?");
$stmt->bind_param("i", $employee_id);

$employee_id = 123; // Example employee ID
$stmt->execute();

$stmt->bind_result($schedule);
$stmt->fetch();

echo "Employee Schedule: " . $schedule;

$stmt->close();
$conn->close();
?>