开发者

why do you have {} around variables in a sql statement?

why do you use {} around variables in following sql statement?

SELECT
FROM users
W开发者_运维技巧HERE username = '{$_POST['user']}' 


I presume you are using SQL from within PHP language.

This syntax with {} is used to interpolate array elements embedded in quoted string.

For example, composing the following string:

"Good morning {$_POST['user']} !"

will compile output with the value of variable (array element) dereferenced, for instance:

"Good morning noname !"

SQL queries in PHP are composed from strings, so this {} syntax is used fairly often.

Reference: Variable parsing - complex syntax PHP4+

p.s. It's always a good idea to provide as many details as possible in your question.


you can with the double quotes, but not with the single quotes. the question uses single quotes, so i am not so sure it is in PHP. (mabee it was misstyped for the question)

so

if $_POST['user'] = "fred";

"Good morning {$_POST['user']} !"

translates as Good morning fred !

but

'Good morning {$_POST['user']} !'

translates as Good morning {$_POST['user']} !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜