Jump to content

Whoops - tablenames!


redbullmarky

Recommended Posts

Hi all

I'm not new to php/mysql, but have pretty much been working as I go along.

I came across a problem today when i wanted to name one of my tables 'references'. I noticed that phpmyadmin was dealing with it fine, and my scripts were causing all sorts of trouble.

The only difference between my scripts and phpmyadmin was that phpmyadmin was enclosing table and fieldnames with a ` mark (like a backwards apostrophe for anyone that can't see that)

So ... my question(s) ... is it good practice to do this to ALL my table names? does it matter apart from when a tablename may share it's name with a mysql function/operator?

Cheers
Mark
Link to comment
Share on other sites

the problem is that "References" is a reserved word in MySQL... you should never be using it as a table name or any name if possible... it will save you a lot of troubles later. But yes, you can use the backticks in order to use reserved words as names if you really want to.

[a href=\"http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html[/a]
Link to comment
Share on other sites

Agreed -- backticks is just MySQL's way of escaping strings into literals so that they don't get interpreted as keywords. But I guarantee you that you'll run into many problems later on down the line. Get into the habit of avoiding such keywords. You can find the list [a href=\"http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html\" target=\"_blank\"]here[/a].
Link to comment
Share on other sites

spot on, thanks guys. unfortunately i've had to do the backtick workaround, as it was the difference between changing several hundred parts one by one or changing just a small section of code.

but definitely one i'll keep in mind for future projects!

Cheers
Mark
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.