SQL is often a complicated piece of code by itself, so you may wish put it inside a "here doc." This will help you read it wherever it appears and test it by itself via a command-line or gui client.$sql = <<<SQLSELECT a.foo, b.bar, c.bazFROM table_a aLEFT JOIN table_b bON ( a.a_id = b.a_id)JOIN table_c cON ( b.c_id = c.c_id)WHERE c.name = $1SQL;