jcanker Posted November 10, 2010 Share Posted November 10, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/218318-apostrophe-vs-single-quote-in-mysql-query/ Share on other sites More sharing options...
ManiacDan Posted November 10, 2010 Share Posted November 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/218318-apostrophe-vs-single-quote-in-mysql-query/#findComment-1132740 Share on other sites More sharing options...
mikosiko Posted November 10, 2010 Share Posted November 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218318-apostrophe-vs-single-quote-in-mysql-query/#findComment-1132762 Share on other sites More sharing options...
ManiacDan Posted November 10, 2010 Share Posted November 10, 2010 Yes, right, it's only good for MYSQL, not the other SQL engines. Nobody really switches databases mid-stream anyway. Backticks aren't going to be the problem when you switch, all the built in functions are. Quote Link to comment https://forums.phpfreaks.com/topic/218318-apostrophe-vs-single-quote-in-mysql-query/#findComment-1132764 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.