...

View Full Version : Table prefixes in PDO



Blaher
11-14-2010, 04:08 PM
Is there any way to add table prefixes in PDO, other than manually concatenating every single table in the SQL statement?

I found a few solutions, but they all have a few problems:
http://stackoverflow.com/questions/1472250/pdo-working-with-table-prefixes - Won't work well with a sub or join query.
http://www.yiiframework.com/doc/api/1.1/CDbConnection#tablePrefix-detail - I really don't want to use the entire Yii framework to get one feature I want.

I was thinking about extending my own version of the PDO class, but I can't think of a correct way to add in the prefix.

MattF
11-14-2010, 04:19 PM
Regex? Basic query types which will precede a table name, so you may need to extend.



$sql_find = array(
'~(FROM\s+)~',
'~(INTO\s+)~',
'~(JOIN\s+)~',
'~(UPDATE\s+)~',
'~(CREATE TABLE\s+)~'
);

$sql_replace = array(
'$1'.$prefix,
'$1'.$prefix,
'$1'.$prefix,
'$1'.$prefix,
'$1'.$prefix
);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum