What are the best practices for integrating PHP with MySQL for survey management?

To integrate PHP with MySQL for survey management, it is best practice to use prepared statements to prevent SQL injection attacks, properly sanitize user input, and securely store database credentials. Additionally, utilizing PDO (PHP Data Objects) for database connections and operations can improve security and performance.

<?php
// Establishing a connection to MySQL database using PDO
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "survey_db";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>