Jump to content

apostrophe vs single quote in MySQL query


jcanker

Recommended Posts

Let me preface this by saying that I've been using php for a while, but never got extremely advanced, so feel free to slap me about for something stupid...

 

I'm working through a jQuery & PHP book, and I've noticed that he's wrapping all his column and table names in the apostrophe ` when making MySQL queries .  In the past I've never done this.  What does the ` do?  I understand about single quotes and double quotes, but haven't come across the ` being used.  What's the deal?

Link to comment
Share on other sites

That's not an apostrophe, that's a "backtick."  An apostrophe and a single quote are the same thing.

 

That being said, you wrap mysql column and table names in backticks to ensure that they're recognized as what they are, this is how you can use a column name like `date`.

 

You don't need them, but technically it's the correct way to write SQL.

 

-Dan

Link to comment
Share on other sites

 

You don't need them, but technically it's the correct way to write SQL.

 

-Dan

 

maybe you should rephrase that  ;)

 

back-ticks are not part of SQL... they are offered in MYSQL to help users to deal with the incorrect usage of MYSQL reserved words, for that case, in MYSQL you can use them if you don't have the option of rename your fields to something different that is not a MYSQL reserved word.

 

The usage of backtick could make your code no portable if in the future you decide to use a different DB Engine and it doesn't support them.

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.