Menu

$CONF['database_prefix' ] crashes

2007-06-21
2013-01-23
  • Donnet, Sylvain

    Donnet, Sylvain - 2007-06-21

    Hello,

    I installed Postfixadmin 2.1.0 on a Linux server with a Postgres database. As I have had an old installed version, I wanted to use the 'database_prefix' capability, to have an other set of tables. It seems it works for any simple query ('SELECT * FROM domain' is transformed into 'SELECT * FROM pa_domain' when database_prefix is for instance 'pa_'), but it crashes on other queries. Is it complex to have workaround for that ? Is there a major bug on this feature ?

    Sylvain

     
    • Greg C

      Greg C - 2007-06-21

      I found that 'alias' instead of '$table_alias' was being used by admin/search.php and overview.php.

      It looks like it should work OK everywhere else.  functions.inc.php sets all the variables $table_* and includes the database_prefix value.

       
    • Donnet, Sylvain

      Donnet, Sylvain - 2007-06-22

      Thanks Greg for this reply.

      But, when I look at functions.inc.php, on v2.1.0, I only have following code for 'database_prefix' management :

         if (!empty ($CONF['database_prefix']))
         {
            if (eregi ("^SELECT", $query))
            {
               $query = substr ($query, 0, 14) . $CONF['database_prefix'] . substr ($query, 14);
            }
            else
            {
               $query = substr ($query, 0, 6) . $CONF['database_prefix'] . substr ($query, 7);
            }
         }

      And, all queries in all other files are hardcoded with the table name : "SELECT * FROM domain WHERE ...". So, any query not having table name beginning at 14th char or at 7th char will fail...

       
    • Donnet, Sylvain

      Donnet, Sylvain - 2007-06-22

      Greg,

      May I suggest to use in all queries something like :
      "SELECT * FROM $CONF['database_prefix']domain, $CONF['database_prefix']alias WHERE ..." (or something shorter)
      as "" will always substitute values. Default being $CONF['database_prefix']='', queries will not be changed by default.

      An other solution could be to configure table names in config.inc.php, as there are not so many tables in postfixadmin :
      $CONF['table_admin'] = $CONF['database_prefix'].'admin';
      $CONF['table_domains'] = $CONF['database_prefix'].'domains';

      This second solution could be more interesting. In my situation, I have an already installed Postfixadmin (2.0.4) and I can have two set of tables to compare, edit, transfert, ...

      Also, I don't if I am the only guy in the world to use Postgresql on Postfixadmin, but I needed to adapt several functions and templates, due to the difference between MySQL and Postgresql. In the last case, 'active' column in several tables is defined as 'boolean', but scripts sometimes test as if boolean (if $...['active'] = "t" in functions.inc.php), sometimes as if integer ("UPDATE ... active=1-active ...").

       
    • Greg C

      Greg C - 2007-06-22

      Make sure you are getting the latest SVN checkout of the trunk code.  If your 2.0.4 is working, it would be easier to let it use tables without prefixes and use the prefix for 2.1.x

       

Log in to post a comment.