Topic: Query without prefix

Hi,

I hava a problem with query.
I modify file header.php
In config I have prefix set to 'forum_'

$query = array(            
    'SELECT'    => 'id, link',
    'FROM'        => 'company',
    'WHERE'        => 'user_id='.$forum_user['id']
 );
           
// $query['PARAMS']['NO_PREFIX'] = 1;

$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

 if (!$forum_db->num_rows($result))
       $companyPresentation = false;
 else
       $companyPresentation = $forum_db->fetch_assoc($result);

I get message

An error was encountered
The error occurred on line 180 in /home2/campecom/public_html/demo.goldproject.pl/forum/header.php
Database reported: Table 'forum_company' doesn't exist (Errno: 1146).

I need query to table 'company' with no prefix.
When I use '$query['PARAMS']['NO_PREFIX'] = 1;' it works, but other standard queries  no work properly.

The question is , how can I sent query with no prefix.

2 (edited by dimkalinux 2011-03-25 14:26)

Re: Query without prefix

Try this code

$query['PARAMS']['NO_PREFIX'] = 1;

$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

unset($query['PARAMS']['NO_PREFIX']); // maybe unset($query);

And dont use num_rows() if u can - it deprecated in punbb-1.4 and will be removed in 1.5.

You can replace num_rows like this

$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
$companyPresentation = $forum_db->fetch_assoc($result);

if (!$companyPresentation)
  error  
else
  ok

Re: Query without prefix

Thanks,

But it cause problem like show below, when I set and then unset $query['PARAMS']['NO_PREFIX']

Notice: Undefined index: poster in site/forum/viewforum.php on line 211

Notice: Undefined index: moved_to in site/forum/viewforum.php on line 213

....

Notice: Undefined index: last_post in site/forum/viewforum.php on line 291

Notice: Undefined index: last_poster in site/forum/viewforum.php on line 291

Probably the best way is change table name or add exception to dblayer files.

Re: Query without prefix

I must see all file with changes for help.