Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2010, 04:08 PM   PM User | #1
Blaher
Regular Coder

 
Join Date: Nov 2005
Location: North Canton, Ohio
Posts: 117
Thanks: 11
Thanked 4 Times in 4 Posts
Blaher is an unknown quantity at this point
Question 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.
Blaher is offline   Reply With Quote
Old 11-14-2010, 04:19 PM   PM User | #2
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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
                );
MattF is offline   Reply With Quote
Users who have thanked MattF for this post:
Blaher (11-14-2010)
Reply

Bookmarks

Tags
pdo, php, prefix, sql, table

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:42 AM.


Advertisement
Log in to turn off these ads.