Jump to content

Archived

This topic is now archived and is closed to further replies.

redbullmarky

Whoops - tablenames!

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

Share this post


Link to post
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]

Share this post


Link to post
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].

Share this post


Link to post
Share on other sites
Using backticks all the time is almost always unnecessary and very cumbersome. Just avoid reserved words.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.