3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 236 Views |
-
Significance of Backticks

22 September 2011 at 12:17am
I was going through some sample codes around the web, and found that backticks (`) are sometimes used to enclose the table names and field names we used in the queries in DataObject:get and DataObject:get_one methods. For example:
$test = DataObject::get_one("Entity", "`Code`='".$data['Code']."'");
What is the significance of enclosing the table names and filed names with backticks? I red some other sample codes in which no backticks are used. Is this something outdated now?
-
Re: Significance of Backticks

22 September 2011 at 12:32am
I'm not sure if that's the case now but in older versions of SS you needed the backticks in order for the framework to keep track of which table to actually fetch from depending on if you're on the draft or the published site. This is of course only relevant for versioned objects and primarily SiteTree and its descendants.
-
Re: Significance of Backticks

22 September 2011 at 3:41am
The only place I use it is when doing something like...
SELECT * FROM Group
because group is a reserved word... backticking is required all the time in the ORM because any relationshp, table or field may be a reserved word.
-
Re: Significance of Backticks

22 September 2011 at 7:44am
You should really be using double quotes (") rather than back ticks (`) as back ticks are MySQL only and sapphire is designed to be database agnostic. This is especially important if you're releasing code as a module.
Also, you should always quote database, table and column names. Once again this is mostly to be database agnostic, though there is also the possibility that in a future version of your current RDBMS, one of these names could become a reserved keyword, or you RDBMS may start treating any non-quoted string as a literal string.
| 236 Views | ||
|
Page:
1
|
Go to Top |



