Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Extending Symfony2 Web Application Framework

You're reading from   Extending Symfony2 Web Application Framework Symfony2 took the great features of the original framework to new levels of extensibility. With this practical guide you'll learn how to make the most of Symfony2 through controlling your code and sharing it more widely.

Arrow left icon
Product type Paperback
Published in Mar 2014
Publisher
ISBN-13 9781783287192
Length 140 pages
Edition Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sebastien Armand Sebastien Armand
Author Profile Icon Sebastien Armand
Sebastien Armand
Arrow right icon
View More author details
Toc

Custom DQL functions


Doctrine can be adapted to many different database vendors such as MySQL, PostgreSQL, and others. To achieve this and still be able to take advantage of the specifics of each underlying platform, Doctrine is designed in such a way that it is easy to define your own custom SQL functions.

We will take advantage of this for our geolocation. In the first chapter, we decided that the home page would only display events within 25 kilometers (which roughly translates to 0.3 in terms of latitude and longitude). To do so, we defined a box of coordinates around a given point and then used it in the SQL code.

However, an actual distance between two points (in a Cartesian plan) is calculated by the following formula:

The preceding formula can be translated to the following SQL query: SQRT (POW(lat_1 - lat_2, 2) + POW(long_1 - long_2, 2) ).

This is correct; however, it is a bit tedious to write, so we'll take advantage of Doctrine's ability to define your own SQL functions and define...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image