The purpose of this assignment is to evaluate a student's understanding of using PHP with MySQL at a basic level.
In this assignment, you will be working with a MySQL database containing two tables: users and orders. The users table contains information about users, and the orders table contains information about orders placed by those users. You will write PHP functions to perform various tasks on the database.
The database schema consists of two tables:
- users(id, name, email)
- orders(id, user_id, product, quantity)
- Complete a PHP function getUsers($database) that retrieves all users from the users table in the database.
- Complete a PHP function getUserById($database, $userId) that retrieves a single user from the users table in the database based on the provided user ID.
- Complete a PHP function insertUser($database, $data) that inserts a new user into the users table in the database.
- Complete a PHP function updateUser($database, $data, $id) that updates a user row in the users table in the database based on the provided user ID.
- Complete a PHP function removeUser($database, $id) that removes a user row from the users table in the database based on the provided user ID.
- Complete a PHP function searchUsersByName($database, $name) that searches for users in the users table in the database based on a provided name, and returns the result in descending order.
- Complete a PHP function getUsersWithOrderQuantity($database) that performs a JOIN operation between the users and orders tables in the database, groups the results by user ID, and returns the total order quantity for each user.