Table prefixes

5 views
Skip to first unread message

cvokk

unread,
Jan 17, 2007, 9:02:37 AM1/17/07
to Php Object Generator
Hallo,
I have read the discussion about the table prefixes on address
http://groups.google.com/group/Php-Object-Generator/browse_thread/thread/dae114621b6baa82/bbda77d59b3a65e2?lnk=gst&q=prefix&rnum=1#bbda77d59b3a65e2

I find this feature very useful, would it be hard to implement?
I was browsing through each classes' code, you could define table
prefix in configuration file and then in the class you would in each
query use something like (excerpt from one of the POG objects)

in Object's (in this example I use News object)constructor would be
something like a

function News($newsText='', $newsDate='', $newsAuthor='',
$newsTitle='', $translationDefId='') {
$this->tablePrefix = $GLOBALS['configuration']['table-prefix'];
...code...
}

so each query with objects table
$this->pog_query = "select * from `news` where
`newsid`='".intval($newsId)."' LIMIT 1";
would be
$this->pog_query = "select * from `".$this->tablePrefix."news` where
`newsid`='".intval($newsId)."' LIMIT 1";

when creating table via pog setup, there could be two possibilities:
(I use pog setup 2.6.1 as a reference)
in file setup_misc.php in function TestCreateStorage
bellow line 614 you can use something like

$tableName = strtolower($className);
$prefixTableName =
$GLOBALS['configuration']['table-prefix'].$tableName;
$sql = str_replace($tableName, $prefixTableName, $sql);
so the correct table with prefix is created

in POG object itself would be query with table name without prefix, so
when creating table manually, user would have to take care about proper
table creation

Or another way how to do it - incorporate into each class public static
method which would return correct sql query for object creation with
regard to user settings - you could use this in pog setup as well

I did not dig very deep into pog setup, because as this is your baby, I
think you would know the best if this change would be sufficient to
make prefixes work.

Anyway, have a good time.

I love pog :)

Reply all
Reply to author
Forward
0 new messages