Single or Double quotes on database input or search

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Single or Double quotes on database input or search

Post by icesolid »

I was just wondering if there is any difference/advantage to using single or double quotes when conducting MySQL queries through PHP.

Example of what I am talking about:

Code: Select all

<?php
$sql = mysql_query("UPDATE `table` SET `username`='name_of_person'");
 
VS
 
$sql = mysql_query('UPDATE `table` SET `username`="name_of_person"');
?>
SEARCHING:

Code: Select all

<?php
$sql = mysql_query("SELECT * FROM `table` WHERE `username`='name_of_person'");
 
VS
 
$sql = mysql_query('SELECT * FROM `table` WHERE `username`="name_of_person"');
?>
Does the single or double quote effect the data being put in or the data being searched in any way? Is one faster than the other?

Thank you for your input in advance.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Single or Double quotes on database input or search

Post by jaoudestudios »

Single quotes for the query are faster because php will not be looking for a variable to parse in the query string...but it is so marginal I would not concern yourself too much with it.

Your update would update every user in the table? Surely you mean to have a WHERE in the query? :P
Post Reply