I'm looking at switching from mysql to mysqli, and I came across this page: http://www.codular.com/php-mysqli. I noticed that, instead of using single or double quotes, the author uses "<<<SQL" (three less than signs SQL) and "SQL" to surround his SQL query. Where can I read more about the significance and proper use of this?
Asked
Active
Viewed 243 times
1
-
1thats called a HEREDOC – Daniel A. White Aug 08 '14 at 22:03
-
1Note that the choice of `SQL` is arbitrary, it could be `EOF` or anything else, but `SQL` is a good choice for wrapping an SQL query. – Dave Morrissey Aug 08 '14 at 22:11
-
Thank you, Daniel and Dave! – Mark Almighty Aug 11 '14 at 13:56
1 Answers
1
<<<
starts a multiline string and is succeeded by the letters that will finish the string. In the case "SQL" on the last line finishes the string.
Look at the accepted answer of Multi-line strings in PHP
Forgot to say about the ;
.
Dave Morrissey responded better (oficial reference), but done it on the comment.
Thank you halfer who corrected some mistakes on the first writing.
-
1Here's the official doc: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc – Dave Morrissey Aug 08 '14 at 22:14
-
@DaveMorrissey Thank you, I think you should add another answer, because your information is way better than mine. – fbiazi Aug 08 '14 at 22:53