add ` to SQL query

Discussion in 'PHP' started by roice, Mar 11, 2011.

  1. #1
    Hello,
    Should I put my varible between ` notes, link: `id` ?
    in this example:
    $query = mysql_query("SELECT id FROM `users` WHERE (first = '$first') AND (`email` = '$email')"); 
    PHP:
    is there any different if I use ` or not?
     
    roice, Mar 11, 2011 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    mysql recognizes backticks(`) as field name and single quote creates strings, so if you use backticks then you can use mysql keyword as field name too.
     
    artus.systems, Mar 11, 2011 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    so in my example - should I use backticks like in EMAIL or withour backticks like in FIRST ?
     
    roice, Mar 11, 2011 IP
  4. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #4
    you can use with or without the backticks unless it is a MySQL reserved keywords, e.g if you have a field name called select or from in your table you need to use backticks.
    It will be better if you use backticks so you can separate field name and strings
     
    artus.systems, Mar 11, 2011 IP