SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Syntax Useage

  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Syntax Useage

    PHP files use variables to store MySQL queries. These queries seem to often be broken down using line breaks in the actual code. Wordpress has many like this, where a query variable will have something along the lines of

    Code:
    INSERT INTO table_name SET
    columnName1 = value1,
    columnName2 = value2;
    ;
    In the above code, you have specific parts in ALL CAPS while each certain part is broken up by line breaks.

    Would this be more of a developer preference than something that is technically / syntactically required? In other words, is it also possible to do things like make the code all 1 line or something like that (I'm currently teaching myself MySQL from Kevin Yank's book "Building Your Own Database Driven Website...")?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Wolf_22 View Post
    is it also possible to do things like make the code all 1 line or something like that
    Yes it is, and it gives a certain someone here great pleasure to read long, complex sql statements written on a single line

    Without kidding, it is only a prefered way of writing. The query runs just as fine written on a single line, or with the MySQL parts written in lowercase.
    But it's so much easier to read and understand (and thus to debug and maintain) if you break it up in multiple lines, and if you use a standard way of layout. I personally like the MySQL parts written in uppercase, as I never use all-uppercase table, field or variable names.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Yes it is, and it gives a certain someone here great pleasure to read long, complex sql statements written on a single line
    lol indeed

    i've stopped answering those questions

    i know it's not fair to the posters if they're new to sitepoint, but queries written on a single line are so user-hostile that i just can't be bothered
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    i know it's not fair to the posters if they're new to sitepoint, but queries written on a single line are so user-hostile that i just can't be bothered
    If I promise not to one-line-it, can I also be in your club?

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    it's a virtual club, and exists only when schrödinger opens the box

    longneck outlined some good points here in a thread called "Writing Readable Queries"
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •