Doctrine raw SQL

$Connection= $EntityManager->getConnection(): Connection;
Get connection
$Statement = $Connection->prepare(string $sql): Statement;
Prepare statement from string
$Statement->bindValue(string|int $param, $value, $type = null): bool
Bind a value to a corresponding name
$Statement->execute(?array $params = null): bool
Execute the statement
$Statement->fetchAll(int $fetchStyle = PDO::FETCH_BOTH): array
Fetch all results
$Statement->fetchOne(int $fetchStyle = PDO::FETCH_BOTH): array
Fetch single result
$Statement->rowCount(): int
Return the number of rows
$Statement->free(): void
Free stored result memory
$connection = $entityManager->getConnection();

$sql = 'SELECT * FROM events WHERE start_date >= :startdate';

$statement = $conn->prepare($sql);
$statement->bindValue('startdate', $startDate->format('Y-m-d H:i:s'));
$statement->execute();

return $statement->fetchAll();
Comments