PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
In my configuration file there is a variable that allows the user to specify the table prefix for the installation of my software. In the event they would like two installations of this software in the same database, they can simply change the table prefix. From my encounters with other CMS's, they use a "wild card" in their SQL so the table prefix is not hard coded. I am aware that str_replace or preg_replace can replace the wild card with the prefix selected in the config file, but what should the wild card be? Joomla! uses #__, but what prevents a column or table from being called that? Sure something like this might work
Im not sure if this is the proper way of doing things but you could start replacing after the FROM in your string. You would probably have to split up your string and then fix it afterwards but its doable.
Or, you could just assume that no one in their right mind would name a table '#__' and save some coding.
watson516 wrote:Im not sure if this is the proper way of doing things but you could start replacing after the FROM in your string. You would probably have to split up your string and then fix it afterwards but its doable.
Thanks. It is not a bad idea, but it the table name doesn't always come after FROM. For example: INSERT INTO `table_name`. I suppose I could create an array of keywords the table name would appear after, but I can't help but think there is a more elegant solution. I am interested in what other people have to say.
I don't know, but I'm the type of programmer who looks both ways while crossing a one way street. As far as I know, a table can be named #__ so I am going to assume someone using my code might name it that.