What are the advantages of using a separate table for storing survey responses in PHP?
When storing survey responses in PHP, it is beneficial to use a separate table in a database to organize and manage the data more efficiently. By separating survey responses into their own table, it allows for easier querying, filtering, and analysis of the data. It also helps to maintain data integrity and scalability as the survey responses grow over time.
// Create a separate table for storing survey responses in PHP
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "survey_database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Create a table for survey responses
$sql = "CREATE TABLE survey_responses (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
respondent_name VARCHAR(50) NOT NULL,
response_text TEXT NOT NULL,
survey_id INT(6) UNSIGNED,
response_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table survey_responses created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
// Close the database connection
$conn->close();