Well I am wondering what is the right way to do the Heredoc syntax?
In my code editor, which is 'e-text editor' doing <<<
totally throws off the syntax highlighting.
and doing << instead doesn't.
code:
private function buildDB() {
// build database
$sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS testDB (
title VARCHAR(150),
bodytext TEXT,
created VARCHAR(100);
)
MYSQL_QUERY;
return mysql_query($sql);
}
Which is the right way? I am still very noobish so no idea.
or maybe I shouldn't rely on syntax highlighting eh? :/
Take a look at example 2: http://php.net/manual/en/language.types.string.php
It is <<<
You need to put the ending MYSQL;
on the beginning of the line without any whitespace. That's why your editor won't highlight it correctly.
The closing of the HEREDOC string most be on a new line without spaces before it , so MYSQL_QUERY;
must be at the start of the line, without whitespace before or after.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.