Page 1 of 1

a few syntax questions.

Posted: Fri May 20, 2005 1:05 pm
by wizbang
Hi,
I can't seem to find a reference to this and I'd like to understand what it means
it's part of a MySQL query written in php that I found on a post.
(i am new to php)

Code: Select all

$sql = "
    SELECT  *
    FROM    `name_of_table`
    WHERE   ".$query."
;"

$res = mysql_query($sql);
What do the periods mean?
Why are they necessary?

Periods don't seem to be needed all the time because i have used
something similar to:
$num = result_of_some_function();
echo "there are $num results";
which embedded the result of the function in the output.

Additionally, in my research so far from the mysql manual on the SELECT statement it indicates nothing about using `s.
i am curious about the following statement

Code: Select all

FROM `name_of_table`
what is the difference between FROM name_of_table and FROM `name_of_table`?

(using the `s) I have written queries with and without. (that's a little troubling if that syntax IS reqired)
Is it necessary is what I am asking.
Thanks for the input.
many regards,
wiz

Posted: Fri May 20, 2005 1:09 pm
by neophyte
In PHP periods/dots are concatenation symbol. Similar to + in JavaScript As far as I know the backticks are optional SQL Syntax

Posted: Fri May 20, 2005 1:16 pm
by McGruff
I almost always use concatenation since syntax highlighting makes it much clearer where the variables are in a string and you don't need to escape double-quotes in html tags. However, linefeeds \n or tabs \t must be double-quoted.

Posted: Fri May 20, 2005 2:07 pm
by Skara
I almost always use concatenation since syntax highlighting makes it much clearer where the variables are in a string
not if you use vim (or something similar). :P

Posted: Fri May 20, 2005 3:11 pm
by Burrito
as for the field names, the "`" are required for field names that might have operators in them:

ex:

FN: the-store would have to have the "`" in them otherwise it will think your subtracting something:

Code: Select all

update myTable set `the-store` = 'bob' where id=54
with that you might actually even be able to have spaces in field names...although I've never tried and prolly never will....