Be Careful with MySQL Field Names

Today's tip is going to be a quick one, but I wanted to share since the solution wasn't completely obvious to me for a while even though I've been using MySQL for several years now on a daily basis.
When naming your fields be sure you don't name them using language that MySQL might attempt to parse as a command. I was going along creating my database, and named a field 'primary' because that was what I'd called the value in the form, and it made sense in context. I then spent a good amount of time scratching my head wondering why all my values were saving in my update SQL I was sending unless this one was included. I realized the problem when I copy and pasted the SQL being run into PHPMyAdmin and saw that the line was breaking after it saw 'primary' in the command and realized my mistake.
Something to keep in mind if your SQL isn't working inexplicably, primary is a pretty common one, but there are a lot of obscure commands that might cause the same result that someone who doesn't administer db's all day wouldn't necessarily know from memory.
Comments
Post new comment