Prepares and executes an SQL query and returns the result as an associative array.
$query = "SELECT * FROM users WHERE age > 25"; $resultSet = $connection->executeQuery($query); $rows = $resultSet->fetchAll(); foreach ($rows as $row) { // do something with the row data echo $row['name'] . '
'; }
$parameters = ['name' => 'John']; $query = "SELECT * FROM users WHERE name = :name"; $resultSet = $connection->executeQuery($query, $parameters); $rows = $resultSet->fetchAll(); foreach ($rows as $row) { // do something with the row data echo $row['age'] . 'This example demonstrates how to use named placeholders in a query with fetchAll(). We pass an array of parameters to the executeQuery() method, which will replace the named placeholders with actual values. The fetchAll() method is then called on the result set to retrieve all the rows. The Doctrine\DBAL\Connection class is a part of the Doctrine DBAL package library, which is a lightweight database abstraction layer on top of PDO.
'; }