I have a long query
$s = $dbh->prepare("SELECT name,type,
(select count(opinionid) from fe_opinion where actor=name) as countopinion,
(select count(commentid) from fe_comment where actor=name) as countcomment,
(select count(commentid) from fe_reply where actor=name and replyto<>null) as countreply,
(select count(voteid) from fe_vote where actor=name and replyto<>null) as countvote,
(select count(voteid) from fe_vote where actor=name and replyto<>null and vote=1) as countagree,
(select count(voteid) from fe_vote where actor=name and replyto<>null and vote=0) as countdisagree
from fs_actor where name=:name");
and It gives me a syntax error when I write it like this in multi line. I am unsure about the compiler because i didnt execute it. Is it supposed to work in this format or should I use heredoc?
How can I continue writing a string from next line? Should ı do it by continuing to next lineby pressing enter? Should I use heredoc or Is there a special new line character?
I’ve found this example in phpdoc
echo 'You can also have embedded newlines in
strings this way as it is
okay to do';
so now I think my syntax error is something else.
Just a shot in the dark here, are you sure it’s not that last comma after
countdisagreethat’s giving you a syntax error? You don’t put a comma after the last part of the SELECT, and you might not have realized you put it there, I know I’ve done that quite a bit myself when breaking up a long SQL query, and it will give a syntax error if it’s there because it’s expecting another statement to select from.SQL queries, multiline or otherwise, should only give a syntax error if there actually is one, so if you get a syntax error, you can bet that you have one. You could break that up so you only have one word on each line and it won’t give a syntax error.