Page 1 of 1

Single or Double quotes on database input or search

Posted: Thu Jan 29, 2009 12:13 pm
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.

Re: Single or Double quotes on database input or search

Posted: Sat Jan 31, 2009 2:21 pm
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