1 (edited by Keulig 2008-01-25 08:54)

Topic: $db->query_build with or without prefix

Hi everyone,

First of all, thanks for the great work you are accomplishing with punbb 1.3. This is gonna be a real masterpiece.

I'm using punbb's database class in my website and I'd like to use the query_build function in it but there is a tiny bit of a problem with the fact that the tables prefix is automatically added within the query.

Could you implement a "$prefix = 1" at the end of the function parameters, and when set to "0", it wouldn't add tables prefix to the query ? (so I could build queries of my own, with other tables than punbb's)

Regards,

Kaelig

Re: $db->query_build with or without prefix

Good point, we'll check it out

Re: $db->query_build with or without prefix

Thanks smile It should be very helpful for portals developpers !

Re: $db->query_build with or without prefix

Wouldn't $prefix="prefix" be better, so it's possible to set a prefix (or none) instead of the default one? Just a thought. smile

5

Re: $db->query_build with or without prefix

intedinmamma wrote:

Wouldn't $prefix="prefix" be better, so it's possible to set a prefix (or none) instead of the default one? Just a thought. smile

That's how it's done now, and I personally can't see how setting $prefix empty in any external scripts, (or to whatever prefix required), is any different to having a toggle within the query itself. I'd agree with you, personally. big_smile

Re: $db->query_build with or without prefix

intedinmamma wrote:

Wouldn't $prefix="prefix" be better, so it's possible to set a prefix (or none) instead of the default one? Just a thought. smile

This feature would be far harder to implement and that's the kind of thing you can do yourself very simply within your php code when building your query array.

Re: $db->query_build with or without prefix

MattF wrote:
intedinmamma wrote:

Wouldn't $prefix="prefix" be better, so it's possible to set a prefix (or none) instead of the default one? Just a thought. smile

That's how it's done now, and I personally can't see how setting $prefix empty in any external scripts, (or to whatever prefix required), is any different to having a toggle within the query itself. I'd agree with you, personally. big_smile

You guys obviously haven't looked at the query builder code wink
Here's some example code:

$sql = 'SELECT '.$query['SELECT'].' FROM '.$this->prefix.$query['FROM'];

Now, how exactly is an extension writer supposed to change the prefix? Your way makes sense (although it's an ugly hack) if you're writing a query with all tables without the prefix. But what if you're just adding one individual table without a prefix to an existing query?

8

Re: $db->query_build with or without prefix

I was just making sure people were on the ball. Honest. http://outgoing.bauchan.org/gifs/nonchwhistle.gif big_smile

Re: $db->query_build with or without prefix

Added in changeset 1308.
This obviously does not solve the issue of easily adding one table without a prefix. However, we think that would be a less common usage of the query builder. In that situation, the extension writer can prepend the prefix to the PunBB tables manually.

10

Re: $db->query_build with or without prefix

Yeah great smile Thanks a lot.