When to use single quotes, double quotes, and backticks in MySQL

后端 未结 13 1055
一个人的身影
一个人的身影 2021-01-26 10:55

I am trying to learn the best way to write queries. I also understand the importance of being consistent. Until now, I have randomly used single quotes, double quotes, and backt

13条回答
  •  耶瑟儿~
    2021-01-26 11:27

    (There are good answers above regarding the SQL nature of your question, but this may also be relevant if you are new to PHP.)

    Perhaps it is important to mention that PHP handles single and double quoted strings differently...

    Single-quoted strings are 'literals' and are pretty much WYSIWYG strings. Double-quoted strings are interpreted by PHP for possible variable-substitution (backticks in PHP are not exactly strings; they execute a command in the shell and return the result).

    Examples:

    $foo = "bar";
    echo 'there is a $foo'; // There is a $foo
    echo "there is a $foo"; // There is a bar
    echo `ls -l`; // ... a directory list
    

提交回复
热议问题