MyBB Community Forums

Full Version: MyBB query errors if $config['table_prefix'] contains ":" (a double colon)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I set $config['table_prefix'] to "mybb:" and the forum refused to work because of MySQLi query error:
MySQLi error: 1064
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 ':datacache' at line 1
Query: SELECT title,cache FROM mybb:datacache

I searched a bit in the code and saw, that table names are just prefixed by the constant TABLE_PREFIX, which is not sufficient. If the TABLE_PREFIX contains a double colon (or any other 'strange' character), the whole table name must be surrounded/quoted by backquotes. At the moment it is not possible to use "mybb:" or similar as the table prefix.
RENAME TABLE mybb:% TO mybb_%

Atleast I think that's the syntax
At database level it works fine, because the database name is not prefixed or suffixed in any way. The problem is at table name level, because every table name (such as "datacache") is prefixed with TABLE_PREFIX.

A workaround is to rename every table to have another prefix without a double colon (such as "mybb_"), but I am not happy with this solution. I wanted my forum tables to be prefixed with "mybb:", but that doesn't work.

The syntax is "RENAME TABLE mybb:datacache TO mybb_datacache" for the datacache table, for the other names resp.

Is it possible to change the MyBB code in that way, to be able to use such names (with double colons or whatever)?
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

Database and table names cannot contain “/”, “\”, “.”, or characters that are not allowed in filenames. 

And : aint allowed in filenames; so can't be used in a prefix or tablename.
^ Windows won't let you use ":" in filenames, however, it'll work on *NIX systems.

Still, dunno if Postgres or SQLite allow them (too lazy to bother checking).
I still wouldn't recommend using ":" characters in table names, however.
It'd be extremely difficult to make MyBB operate in such a way. You'd have to escape every instance of the table names with `.

So in a query,

".TABLE_PREFIX."posts becomes ".TABLE_PREFIX."posts

The updaet/insert/simple query methods could just be modified to change that functionality too.

This isn't something that MyBB supports.
I tested another character, which is allowed in filenames, namely a dash (-):
$config['table_prefix'] = "mybb-";
MyBB refused to work with the same error as above (syntax error at '-datacache').
That is for the same reason above.