-1

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 ...

S. Walker
  • 53
  • 7

2 Answers2

0

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 :)

Edwin Lambregts
  • 408
  • 6
  • 22
0

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.

Ashkan Arefi
  • 665
  • 4
  • 7