Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Table prefixes in PDO
11-14-2010, 05:08 PM #1
- Join Date
- Nov 2005
- North Canton, Ohio
- Thanked 4 Times in 4 Posts
Table prefixes in PDO
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/1...table-prefixes - Won't work well with a sub or join query.
http://www.yiiframework.com/doc/api/...ePrefix-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.
11-14-2010, 05:19 PM #2
- Join Date
- Jul 2009
- South Yorkshire, England
- Thanked 304 Times in 303 Posts
Regex? Basic query types which will precede a table name, so you may need to extend.
Code:$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 );
Users who have thanked MattF for this post: