I prefer the Heredoc syntax, although Nowdoc will also work for your example:
Heredoc:
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Nowdoc: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
The advantage of both is that you can copy and paste direct SQL into and out of this block without having to run or format it. If you need to enable parsing, for example, you will use variables from a string with two quotes, you should use Heredoc. Nowdoc behaves like single quotes.
Nowdoc:
public function findSomethingByFieldNameId($Id) { $sql = <<<'SQL' SELECT field1, field2, field3 as Field3_Something, field4, field5, field6, field7, field8, field9 FROM table JOIN table2 AS TNS ON TNS.id = table.id WHERE something = 1 SQL; return $this->db->fetchData($sql, null, 'all'); }
Heredoc:
public function findSomethingByFieldNameId($Id) { $sql = <<<SQL SELECT field1, field2, field3 as Field3_Something, field4, field5, field6, field7, field8, field9 FROM table JOIN table2 AS TNS ON TNS.id = table.id WHERE something = '$Id' SQL; $sql = mysql_real_escape_string($sql); return $this->db->fetchData($sql, null, 'all'); }
philwinkle
source share