What best practices were recommended for structuring the database tables and PHP code to handle hotel room bookings effectively?
To handle hotel room bookings effectively, it is recommended to have separate database tables for rooms, bookings, and customers. Each booking should be associated with a specific room and customer, with relevant information such as check-in and check-out dates. In the PHP code, use prepared statements to prevent SQL injection and ensure data integrity.
// Database table structure for rooms
CREATE TABLE rooms (
id INT PRIMARY KEY,
room_number INT,
type VARCHAR(50),
price DECIMAL(10, 2)
);
// Database table structure for bookings
CREATE TABLE bookings (
id INT PRIMARY KEY,
room_id INT,
customer_id INT,
check_in_date DATE,
check_out_date DATE,
total_price DECIMAL(10, 2),
FOREIGN KEY (room_id) REFERENCES rooms(id),
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
// Database table structure for customers
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(50)
);