Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Significance of Backticks

Go to End

5 Posts   737 Views


Community Member, 7 Posts

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?


Community Member, 288 Posts

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.


Forum Moderator, 1899 Posts

22 September 2011 at 3:41am

The only place I use it is when doing something like...


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.


Community Member, 7 Posts

22 September 2011 at 4:20am

Got it, thank you guys!


Community Member, 473 Posts

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.