Forum Moderators: coopster

Message Too Old, No Replies

Why use 'curly braces' in mysql query() statments?

         

ryan_b83

3:52 am on Nov 22, 2006 (gmt 0)

10+ Year Member



Hello, I was just going through some code I found on the net. I'm pretty decent with PHP/MySQL but I have ever seen curly braces used in the sql statments until i saw this script.

mysql_query ("DELETE FROM table WHERE col={$value}");

What would be the reason for the {}?

Thanks,
Ryan

eelixduppy

3:57 am on Nov 22, 2006 (gmt 0)



It's just another way to put variables inside of a string in PHP. You can omit the braces in your example and it will have no affect.

Refer to STRINGS [us2.php.net] for more details. :)

pixeltierra

4:18 am on Nov 22, 2006 (gmt 0)

10+ Year Member



{} are needed for interpolating array elements and complex object references inside double quotes.

"hi {$family_member['mom']}, long time no talk."
"hi {$this->people->family->mom} long time no talk."

If you wanted to change the above vars to a simple one, you might not bother taking out the {}.