Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    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:

    Blaher (11-14-2010)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •