1 (edited by darrenwhitlen 2009-03-24 15:52)

Topic: Database in static page

I'm creating a few static pages that integrates with PunBB.

Using this code: http://pastebin.com/f19233d24, line 24 throws a database error:
    "Database reported: not an error."
But I can't seem to find anything wrong with it?

I had taken the query from another PunBB page and changed as needed, but no dice.
Are their any PunBB database functions I'm missing?

Thanks for any help!

2

Re: Database in static page

Try changing this line:

FROM'          => 'topics AS t, posts AS p'

to:

FROM'          => 'topics AS t INNER JOIN posts AS p'

It may need a LEFT JOIN if that doesn't work.

3 (edited by darrenwhitlen 2009-03-24 16:20)

Re: Database in static page

Both
    'topics AS t INNER JOIN posts AS p'
and
    'topics AS t LEFT JOIN posts AS p'

return the same error sad

I'm using the sqlite backend if that changes anything?

4

Re: Database in static page

I honestly can't suggest anything else, offhand. I'm not exactly familiar with the new query builder. One of the 1.3* chaps may be able to proffer a suggestion.

5

Re: Database in static page

You shouldn't use $forum->query but $forum->query_build.

Re: Database in static page

Ahh thank you pepak, that got me further!

I am now getting the follow error:

Database reported: SQL logic error or missing database (Errno: 1).

$query = array(
    'SELECT'    => 't.id, t.poster, t.subject, t.posted, t.first_post_id, t.sticky, p.message',
    'FROM'        => 'topics AS t, posts AS p',
    'WHERE'        => 't.forum_id=2 AND p.topic_id=t.first_post_id',
    'ORDER BY'    => 't.sticky DESC, t.posted DESC',
    'LIMIT'        => '5'
);

I have tried the 2 changes MattF mentioned earlier too, same error.
Shouldn't the errors be a little more.. descriptive? Would make things easier.

7

Re: Database in static page

Add

define('FORUM_SHOW_QUERIES', 1);

to the end of your config.php. This will display performed queries and you can check what's wrong with them, e.g. in PhpMyAdmin.

Re: Database in static page

That has made things easier. Was missing the table prefixes off sad

Thanks for the tip pepak smile

Re: Database in static page

If you use more than one table in FROM or JOINS, you should add a prefix manually to the tables, and add this parameter to the query builder:

'PARAMS' => array('NO_PREFIX' => true),

Re: Database in static page

That makes sense Slavok. Is there a list or any documentation that covers the 'PARAMS' parameter of the query builder?
Or any documentation on the internals of PunBB at all?