DEV Community

David Kanekanian
David Kanekanian

Posted on

E3 - Adapting PHP Code to Specify the User

In the previous examples, you used the root user to connect to your database and the password was an empty string. Now, replace the username and password with the specified username and passwords above.

  • Root user - as in previous examples, the user name was "root" and password was an empty string. Any queries by the root user are allowed full access privileges to all your tables.
$databaseLink = new mysqli("localhost", "root", "", "NeatTreats");
Enter fullscreen mode Exit fullscreen mode
  • Customer user - the username is "Customer" and the password is "CustomerPassword123". Only SELECT queries on the product table can be made from this database link.
$customerDatabaseLink = new mysqli("localhost", "Customer", "CustomerPassword123", "NeatTreats");
Enter fullscreen mode Exit fullscreen mode
  • Admin user - the username is "Admin" and the password is "AdminPassword123". Only SELECT, UPDATE and DELETE queries on the product table can be made from this database link.
$adminDatabaseLink = new mysqli("localhost", "Admin", "AdminPassword123", "NeatTreats");
Enter fullscreen mode Exit fullscreen mode

Parent topic: Example 3

Top comments (0)