Code summary
The cleaned backend removes the weakest parts of the original exercises.
The main improvements are configuration separation, centralized database access, validation before insert, and prepared statements for database writes.
Database settings are isolated in one file so credentials are not repeated across handlers.
return [
'db_host' => '127.0.0.1',
'db_port' => 3306,
'db_name' => 'flowledger',
'db_user' => 'root',
'db_password' => '',
];
The create handler builds a normalized payload, validates it, prepares the SQL statement, then binds values in the expected column order.
$statement = $connection->prepare(
'INSERT INTO customers
(customer_id, first_name, last_name, gender, email, phone, address)
VALUES (?, ?, ?, ?, ?, ?, ?)'
);
The listing page keeps the read query simple and focuses on returning a complete view of each customer record.
$result = $connection->query(
'SELECT customer_id, first_name, last_name, gender, email, phone, address, created_at
FROM customers
ORDER BY created_at DESC'
);