dongre6270
dongre6270
2013-04-16 13:28

PHP MySQL语法引用点[重复]

已采纳

This question already has an answer here:

I'm really confused about the difference and when should I write like that in MySQL queries between :

`".$variable." `

' ".$variable." '

" '.$variable.' "

'$variable'

In other words what's the rule of quotes, dots ...

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doudui2229 doudui2229 8年前

    This is a variable: $a


    This is a string: "hello world"


    This is a string: 'hello world'


    You can join variables & strings by dot:

    $b = $a . "hello" . $a . 'world';
    

    or use variable inside " "

    $b = "hello $a world" ;
    $b = "hello" . $a . "world" ;
    $b = 'hello' . $a . 'world' ;
    

    You can not use variables inside '


    ` use in mysql for field & table titles.


    ' use in mysql for variables.

    点赞 评论 复制链接分享
  • dongzen5577 dongzen5577 8年前

    It depends on the way you build your query.

    In example, I like to build my queries somewhat like this:

    "SELECT name FROM table WHERE table_id='".$id."'"
    

    The double quotes are to close (and later re-open) the statement, single quotes simply mean that it's something of a string (in my example I'm using an integer, but words should be encapsulated in single quotes). The dots are PHP-related: they simply connect/paste stuff together.

    Hope my answer has been of use to you :)

    点赞 评论 复制链接分享

相关推荐