tags:

views:

47

answers:

2

I have a project management website running on PHP and MySQL. But I am not the person who developed it, which makes it harder for me to figure out what the problem is. So I turned to stack overflow.

When I try to sort a list of objects, MySQL server throws an exception at me, saying:

"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY company_id' at line 10".

So I searched throughout the entire source code for "GROUP BY company_id", and found one occurrence, which was not at line 10, first of all, and second, I didn't see anything wrong with it.

That line looked like:

$sql .= " GROUP BY company_id
          ORDER BY $orderby";

$rows = db_loadList( $sql );

I have tried researching on this topic, but could not find anything specific. I know this is really not enough information, but I just want to know in general what could possibly cause this problem and if any of you have ever seen it before.

Any kind of input would be greatly appreciated. Thanks,

Vlad

A: 

If I had to predict the problem, I'd guess that the $orderby was empty or invalid. Alternatively, there was some other GROUP BY clause (or ORDER BY, or HAVING) clause ahead of the fragment you show.

Print the SQL - the whole statement.

If the problem is not obvious, add it to your question.

Jonathan Leffler
Hi, thanks for your suggestions. As I started digging even deeper into the code, I figured out that the only file that contains a string GROUP BY company_id, is never used. So now I am going through the trouble of finding where this string could be generated, and it is taking a very long time, because there are thousands of files, and I do not know which ones are actually involved in the process of building a string. So if you could please give me a couple days, I might be able to find something. Thank you again, I will get back to you soon with more details.
Vlad
A: 

Hi, so I figured out the problem. it wasn't actually an SQL problem. The problem was caused by the way a request string was built. I realized that there were two question marks instead of a one (i.e. "??") at the beginning of the request string. That was causing the SQL server to complain about syntax for some reason. But thank you all anyway for your effort.

Best of luck,

Vlad

Vlad