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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Significance of Backticks


Go to End


5 Posts   1074 Views

Avatar
kpower

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?

Avatar
MarcusDalgren

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

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.

Avatar
kpower

Community Member, 7 Posts

22 September 2011 at 4:20am

Got it, thank you guys!

Avatar
(deleted)

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.