a good programming practice to place sql syntax spaces

+2 Yousef Al-Hadhrami · December 1, 2014
Just was woundering, which is better to get used to when assembling an sql query syntax on PHP, to put space before concatenating or after concatenating?

    $query = "SELECT * ";
    $query .= "FROM user_names ";
    $query .= "WHERE activated = 1 ";
    $query .= "ORDER BY score ASC"; 


    $query = "SELECT *";
    $query .= " FROM user_names";
    $query .= " WHERE activated = 1";
    $query .= " ORDER BY score ASC"; 

I seen that most programmers do the 1st example but I think the second one is better because it is more visible and easy to insert a space when a new related query is added.
so what you think?

Post a Reply


Oldest  Newest  Rating
0 Jason Amador · December 1, 2014
I personally think the first example looks better.  I guess if you're working alone do what you like, otherwise your employer can tell you what they like.
  • 1

SQL & Databases


Everything SQL and Databases related in here!

Bucky Roberts Administrator