Mysql brackets?

Latelly I saw many PHP / MySQL questions that include SQL values ​​in {}, for example:

SELECT * FROM table WHERE field LIKE '{$value}';

What's up with that? Is it really? Why do so many people use this weird (at least for me) syntax?

+3
source share
2 answers

From php.net :

Complex (curly) syntax

This is not called complex because the syntax is complex, but because it allows you to use a complex expression.

. , , }. { , , $ {. {\ $, literal {$.

+7

, , , :

$SQL = "Select * FROM table WHERE field LIKE '{$value[5]}'";

.

PHP.net

$beer = 'Heineken';
echo "$beer taste is great"; // works; "'" is an invalid character for variable names
echo "He drank some $beers";   // won't work; 's' is a valid character for variable names but the variable is "$beer"
echo "He drank some ${beer}s"; // works
echo "He drank some {$beer}s"; // works

http://php.net/manual/en/language.types.string.php

+6

Source: https://habr.com/ru/post/1730671/


All Articles