R
R
rekrios2015-08-27 13:24:27
PHP
rekrios, 2015-08-27 13:24:27

Why by coding style (php) concatenation in SQL?

Why use string concatenation in SQL? framework.zend.com/manual/1.12/en/coding-standard....
Example from the document above:

$sql = "SELECT `id`, `name` FROM `people` "
     . "WHERE `name` = 'Susan' "
     . "ORDER BY `name` ASC ";

Head example:
$sql = "SELECT `id`, `name` FROM `people` 
     WHERE `name` = 'Susan' 
     ORDER BY `name` ASC ";

As for me, the second option is much more readable, especially in the case of a large request? What's the point?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy Orlov, 2015-08-27
@rekrios

You misunderstood a little, there are key points:
Well, it can be convenient for various reasons, for example, write comments or comment out some line:

$sql = "SELECT `id`, `name` FROM `people` "
           . "WHERE `name` = 'Susan' "
// закомментировано на время отладки
//           . "ORDER BY `name` ASC "
           . "ORDER BY `name` DESC LIMIT 5"
;

S
synapse_people, 2015-08-27
@synapse_people

ну как же, на сервер идет в несколько байт меньше данных)
аля всякие \t и \n...
+ некоторые IDE сами переносят код

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question