What are the different methods for retrieving data from a database in PHP?

To retrieve data from a database in PHP, you can use various methods such as using the mysqli extension, PDO (PHP Data Objects), or ORM (Object-Relational Mapping) libraries like Eloquent. These methods allow you to connect to the database, execute SQL queries, and fetch the results in a structured format for further processing in your PHP application.

// Using mysqli extension
$connection = mysqli_connect('localhost', 'username', 'password', 'database');
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

while($row = mysqli_fetch_assoc($result)) {
    // Process each row of data
}

mysqli_close($connection);