redbullmarky Posted March 1, 2006 Share Posted March 1, 2006 Hi allI'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?CheersMark Quote Link to comment Share on other sites More sharing options...
jworisek Posted March 1, 2006 Share Posted March 1, 2006 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] Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2006 Share Posted March 1, 2006 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]. Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 1, 2006 Share Posted March 1, 2006 Using backticks all the time is almost always unnecessary and very cumbersome. Just avoid reserved words. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted March 2, 2006 Author Share Posted March 2, 2006 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!CheersMark Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.