In what ways can a PHP developer ensure data integrity and security when handling sensitive patient information in a hospital information system project?
To ensure data integrity and security when handling sensitive patient information in a hospital information system project, a PHP developer can implement measures such as input validation, using parameterized queries to prevent SQL injection attacks, encrypting sensitive data, and implementing access controls to restrict unauthorized access to the data.
// Example of input validation to prevent SQL injection
$patientName = $_POST['patient_name'];
$patientName = mysqli_real_escape_string($conn, $patientName);
// Example of using parameterized queries to prevent SQL injection
$stmt = $conn->prepare("SELECT * FROM patients WHERE patient_id = ?");
$stmt->bind_param("i", $patientId);
$stmt->execute();
// Example of encrypting sensitive data
$encryptedData = openssl_encrypt($sensitiveData, 'AES-256-CBC', $encryptionKey, 0, $iv);
// Example of implementing access controls
if($_SESSION['role'] !== 'doctor'){
die('Access denied');
}