Menu

Table prefix

Hans T
2002-12-06
2002-12-10
  • Hans T

    Hans T - 2002-12-06

    Other than Search and Replace, is there a way to add a prefix (phpay_item instead of item) to each table?
    Since not all queries start with CAPITALS and not all references to each table is the same, this is a hard job to do.

     
    • Andreas Kansok

      Andreas Kansok - 2002-12-10

      In support area you'll find a modified db_func.inc.php for this cases.
      This replaces all tables names in var $query with a RegularExpression to $prefix+tablename.

      Or use following db_query()-function instead:

      function db_query($query, $rp=1) {
        global $db_type, $link, $stmt, $counter, $item, $f_row;
        if ($rp == 1) {
          $prefix="shopst_";
          $tables = array("abt", "cart", "click", "color", "currency", "item", "itemgr",
                       "language", "link", "online", "package", "packinfo", "payment", "price", "pricetype", "shipment", "size",
               "statistics", "user", "usrgroup");
          foreach ($tables as $table) {
            if (ereg("\ ".$table, $query)) {
          if ($table!="user") $query=preg_replace("(".$table."(?!(ID|gr)))"," ".$prefix.$table, $query);
              else $query=preg_replace("(".$table."(?!(ID|gr)))"," ".$prefix.$table, $query,1);
            }
          }
        }
        if ($rp==3) { echo "$query <br>\n"; }
        if ($db_type == "mysql"){
          return mysql_query($query);
        }
      }

       

Log in to post a comment.