Hey guys,
I'm currently working on a project where I need to fetch multiple rows from a MySQL database using PHP. I also want to assign the returned rows to a variable for further processing. But I'm a bit stuck on how to achieve this.
Here's some relevant information about my project:
1. I'm using object-oriented programming (OOP) in PHP.
2. I have already established a connection to the MySQL database.
3. I have a table in the database called "users" with columns like "id", "name", and "email".
Now, what I want to do is fetch multiple rows from the "users" table and store those rows in a variable in my PHP code. I want each row to be accessible as an object or an associative array.
I would really appreciate it if anyone could guide me on how to write the PHP code to accomplish this. Specifically, I'm not sure how to loop through the multiple rows and store them in a variable.
Thanks in advance for your help!

Hey everyone,
I wanted to chime in and share my personal approach to fetching multiple rows from a MySQL database using OOP PHP and the mysqli extension.
To accomplish this, I found it convenient to utilize a while loop along with the fetch_assoc() function.
Here's a code snippet that demonstrates how you can do that:
In the code above, after preparing the query using `$connection->query()`, we check if any rows are returned using `$result->num_rows`. If rows are found, we initialize an empty array and use a while loop to fetch each row and store it in the array using `$rows[] = $row`. You can access individual row elements directly if required.
Feel free to modify the code based on your specific project requirements. If you have any further questions, feel free to ask. Good luck with your implementation!