Q:

simple php Dollar $ evaluation in string questions

I have always been confused that .e,g in php i have sql statement
$qry = "select * from table where id = $id";

now can i insert "$" directly inside the quotes or i have to use
 $qry = "select * from table where id =".$id." ";

or
 $qry = 'select * from table where id = $id';

or 
 $qry = 'select * from table where id = '$id'';

Which is correct

A:

None of the above, unless $id happens to be SQL escaped already. You'll probably want to use this, assuming you're using MySQL:
$qry = "select * from table where id = '".mysql_real_escape_string($id)."'";

Edit: Okay, that was incorrect. As per the comment on my answer, this should work:
$qry = "select * from table where id = ".(int)$id;

A:

If the string is in double quotes, variables will be evaluated. If it's in single quotes, it's literal and you'll get exactly what you type.
$bar = 42;
'Foo $bar Baz'           // Foo $bar Baz
"Foo $bar Baz"           // Foo 42 Baz
'Foo ' . $bar . ' Baz'   // Foo 42 Baz
'Foo ' . '$bar' . ' Baz' // Foo $bar Baz
"$bar " . $bar . " $bar" // 42 42 42    

Here is the relevant manual section for a full explanation:
http://php.net/manual/en/language.types.string.php#language.types.string.parsing
To put actual quotes into the string, you'll need to alternate them or escape them.
'"$bar"'    // "$bar"
"'$bar'"    // '42'
'\'$bar\''  // '$bar'
"\"$bar\""  // "42"
''$bar''    // syntax error, empty string '' + $bar + empty string ''

Also, what he said.

