[wp-testers] Error in SQL syntax?

Ryan Boren ryan at boren.nu
Wed Jan 31 19:38:40 GMT 2007


On 1/31/07, Joefish <joefish.testers at feastofcrumbs.com> wrote:
> On 1/31/07, Alex Leung <sixsteps at gmail.com> wrote:
> > I just realized that I'm getting this error on my Links page:
> > http://www.sixsteps.org/links/
> >
> > *WordPress database 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 '' at line 1]
> > SELECT cat_id, cat_name FROM
> >
> > *** Can anybody shed some light on this?
>
> (snip)
>
> I ran into something very similar with a friend. Try changing this:
>
> $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM
> $wpdb->linkcategories");
>
> into this:
>
> $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM
> $wpdb->categories WHERE link_count > '0'");
>
>
> That modified SELECT worked just fine for my friend, but then we also
> needed to tweak the rest of his custom function.


Or get_categories('type=link').  That way you are insulated from DB
schema changes.  Using API instead of SELECTs when possible makes
forward compatibility much easier to maintain.

Ryan


More information about the wp-testers mailing list