Page 1 of 1
db queries & single quotes?
Posted: Wed Aug 20, 2003 9:54 pm
by nigma
Hey, when you are doing a mysql_query() and such which of the following examples is better:
їcode]mysql_query("select name from names");ї/code]
їcode]mysql_query("select name from 'names'");ї/code]
Posted: Thu Aug 21, 2003 1:58 am
by devork
Code: Select all
mysql_query("select name from 'names'");
i think this is good makes things clear
Posted: Thu Aug 21, 2003 3:52 am
by jollyjumper
throws an error at my mysql database, but
does work, so I would say that the first option is the only option.
Greetz Jolly.
Posted: Thu Aug 21, 2003 8:15 am
by DaMastaBugz
I think this is kind of a personal issue.
I know people who prefer to use single quotes and people who just hate that. I fall into the second group.
In cases where you name your tables "my table" (not the space in the name) the single quotes are a must, but if you are a reasonable bloke, you'd never name your tables with special characters and spaces to start off.
Hope this helps
Posted: Thu Aug 21, 2003 9:41 am
by patrikG
I am not aware of that using single or double quotes make a difference in MySQL.
However they make a huge, but very subtle difference in PHP. Everything between double-quotes will be get parsed, i.e. searched for variables which will get replaced with their value.
Everything between single-quotes is taken as text.
Example:
Code: Select all
$var='cookie';
echo "my $var is different";
echo 'my $var is different';
Depending on how much text there is between the double-quotes, this parsing slows the output down. Hence, most people use single quotes.
Posted: Thu Aug 21, 2003 10:26 am
by nigma
Thanks a bunch guys.
Posted: Thu Aug 21, 2003 1:53 pm
by Coco
yup
and i single quote all php strings, and keep the double quotes for insides strings: sql 'output' and html
its easy to remember when you have a specific system you use (like i always use single quotes and concat to put in a variable)
Much less confusion when you try to read it later on
