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

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay