Error in your SQL syntax

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 20, 2010   (RSS)

Hi there, having an issue with this code which I am using on another site (different host) without any problem... not sure if it is my code or version of mysql (version: 5.0.22)??

<?php
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => 'active ="1"' . ' AND show ="1"',
'loadUploads' => '0',
'allowSearch' => '0',
));
?>


Error:

MySQL Error: 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 'show ="1") ORDER BY dragSortOrder DESC' at line 3

Re: [Dave] Error in your SQL syntax

Got it sorted :)

I changed the name of the field "show" and it now works. I guess that reserved for something.

Cheers,
Jan

Re: [Dave] Error in your SQL syntax

By Dave - January 20, 2010

I was just going to post a follow up on this one that 'show' is in fact a reserved mysql word:
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

And a trick for dealing with those is either renaming the field -or- surrounding it with `backticks` (beside the 1 on most keyboards) like this:

'where' => 'active ="1"' . ' AND `show` ="1" ',

Backticks are of telling MySQL that you mean a table or fieldname and not anything else.

Most of the time it's just easier to rename the field, though. :)
Dave Edis - Senior Developer
interactivetools.com