I've just started to learn PHP. What I am trying to do a very simple sql select statement-
$sql = 'SELECT firstname, lastname,email
ORDER BY firstname where id=12';
Could not connect to the database testdb :SQLSTATE: Syntax error or access violation: 1064 You have an error in your SQL syntax;
Your query is in the wrong order,
order by needs to be after the
SELECT firstname, lastname,email FROM MyGuests where id=12 ORDER BY firstname
You can see the order for all functions in the manual, http://dev.mysql.com/doc/refman/5.7/en/select.html.