Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

Backticks in MySQL queries?????

Aloittaja Krashsite, heinäkuu 28, 2013, 03:52:55 AP

« edellinen - seuraava »

Sir Osis of Liver


Just wasted several hours 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?

When in Emor, do as the Snamors.
                              - D. Lister

butch2k

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.

emanuele

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.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

MrPhil

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?

Sir Osis of Liver


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

When in Emor, do as the Snamors.
                              - D. Lister

Advertisement: