Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP, MySQL, quotes and backquotes

PHP, MySQL, quotes and backquotes
Thread Tools
Love Calm Quiet
Mac Elite
Join Date: Mar 2001
Location: CO
Status: Offline
Reply With Quote
Jan 22, 2006, 09:38 AM
 
A search of forum re: "Backquotes" doesn't show much.

In my beginning-level PHP/MySQL books I find it usually well specified when to use single, when double quote. But when I EXPORT via PHYMyAdmin to back up a DB, they often use a single BACKQUOTE. And I seem to remember that in debugging a problem once that replacing a single with a BACKquote fixed a problem.

anybody got a simple summary of the difference of when each should be used?
TOMBSTONE: "He's trashed his last preferences"
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jan 22, 2006, 02:26 PM
 
Originally Posted by Love Calm Quiet
A search of forum re: "Backquotes" doesn't show much.

In my beginning-level PHP/MySQL books I find it usually well specified when to use single, when double quote. But when I EXPORT via PHYMyAdmin to back up a DB, they often use a single BACKQUOTE. And I seem to remember that in debugging a problem once that replacing a single with a BACKquote fixed a problem.

anybody got a simple summary of the difference of when each should be used?

I don't really use either, I rely on the htmlspecialchars function with form input.
     
moodymonster
Mac Elite
Join Date: Sep 2003
Location: London
Status: Offline
Reply With Quote
Jan 22, 2006, 02:40 PM
 
single quote tells PHP just to look for escaped characters eg

Code:
$my_var = 'what\'s up, ' . $user_name;
double quote tells PHP to essentially read the whole string and replace variable references with the actual value without having to . join the text eg
Code:
$my_var = "what's up, $user_name";
note that if you had a double quote inside a double quoted string, you'd have to escape the inner ones.

Using single quotes is supposed to be faster because it is less work for PHP to do, you're telling PHP to read the whole string looking for variables when you double quote. Also it is simpler when using values from an array.

With regard to backquotes - outside of MySQL outputs, I've not encountered or used them.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jan 22, 2006, 02:44 PM
 
Originally Posted by moodymonster
single quote tells PHP just to look for escaped characters eg
You can also use escaped characters in double quote strings, just FWIW...

With regard to backquotes - outside of MySQL outputs, I've not encountered or used them.
The official docs provide examples for using backquotes in MySQL insert statements, e.g.:

Code:
INSERT INTO mydb.mytable (`field1`, `field2`) VALUES ('$field1', '$field2')
     
moodymonster
Mac Elite
Join Date: Sep 2003
Location: London
Status: Offline
Reply With Quote
Jan 22, 2006, 03:22 PM
 
one other thing, if you use \n - it doesn't seem to work inside single quotes, only double. Doesn't effect the output unless you want to read your created HTML code, in which case it'll make your life a lot easier.

I tend to create things using arrays and foreach loops imploding them at the end adding "\n" to them as the implode separator.
     
jay3ld
Senior User
Join Date: Jul 2004
Status: Offline
Reply With Quote
Jan 22, 2006, 04:21 PM
 
i prefer using single quotes. you are most likely more often to use a double quote when wrighting bits and pieces though php so this just takes the hassle of all those \" when a single quote does not come along as often.
i think to get the \n to work you can do.
echo 'Words' . "\n";
that should work. but i do not really care. i would rather have it so people trying to read my html code to find out how i did something to have a harder time reading it and piss them off
     
madmacgames
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Jan 22, 2006, 05:39 PM
 
backquotes are used to enclose the names of tables and columns. If you don't use them and you have tables or columns whose name is a mysql keyword (which is not all that uncommon), you could run into problems. This is in MySQL statements.

Within PHP itself, backquotes have quite a different purpose, which is to execute shell commands.
( Last edited by madmacgames; Jan 22, 2006 at 05:45 PM. )
The only thing necessary for evil to flourish is for good men to do nothing
- Edmund Burke
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:20 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,