Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Sir Osis of Liver - heinäkuu 28, 2013, 03:52:55 AP

Otsikko: Backticks in MySQL queries?????
Kirjoitti: Sir Osis of Liver - heinäkuu 28, 2013, 03:52:55 AP

Just wasted several hours (https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.thekrashsite.com%2Fpics%2Fhairpull1.gif&hash=d1684c7b73ef4c7cc773994cfce0795f18f1c1d9) trying to make a mysql query work.  What appeared to be single quotes around field names in some sample code were actually grave accents, aka backticks ` (ASCII 96), a character I've never used in all the years I've been using computers.  Can barely see things like that, especially this late at night, but used a magnifier widget and thought they looked funny, so replaced them all with single quotes, which made matters worse.  Turns out they are used to escape mysql reserved words, which I wasn't using, but apparently phpmyadmin insists on having them around field names when creating a table.

Has anyone else run into this?

Otsikko: Re: Backticks in MySQL queries?????
Kirjoitti: butch2k - heinäkuu 28, 2013, 04:30:05 AP
Yes phpmyadmin has been using it for years, as you underlined it is used for escaping reserved keywords. phpmyadmin adopts a better be safe than sorry attitude, even when backquotes are of no use.
Otsikko: Re: Backticks in MySQL queries?????
Kirjoitti: emanuele - heinäkuu 28, 2013, 08:14:46 AP
You can either use ` or nothing for tables and fields (when you write your own query in phpMyAdmin), the problem is that you *cannot* use ' (single quotes) to delimit table names or fields, otherwise the text is interpreted as a string and not as field name and the query generates an error.
Otsikko: Re: Backticks in MySQL queries?????
Kirjoitti: MrPhil - heinäkuu 28, 2013, 10:16:59 AP
Putting backticks ` around table and field names, in case they happen to be reserved words, is standard practice in the database world (MySQL, at least). It's overkill in most cases, but doesn't hurt. I doubt that any effort will be made to remove them from SMF. That said, yes they can be difficult to tell apart from single quotes '. Perhaps you could configure your editor to make them blink or be a different background color? Or use a larger font size? Or get new glasses? Or go to bed on time?
Otsikko: Re: Backticks in MySQL queries?????
Kirjoitti: Sir Osis of Liver - heinäkuu 28, 2013, 03:31:15 IP

Should have learned this stuff when I was a lot younger and all of my parts still worked. :P