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

Significance of Backticks


5 Posts   375 Views


22 September 2011 at 12:17am Community Member, 7 Posts

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?


22 September 2011 at 12:32am Community Member, 288 Posts

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.


22 September 2011 at 3:41am Forum Moderator, 1796 Posts

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.


22 September 2011 at 4:20am Community Member, 7 Posts

Got it, thank you guys!


22 September 2011 at 7:44am Forum Moderator, 474 Posts

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.