We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1764
    • 680 Posts
    It seems to me it would be nice to have an automatic table prefix ability in the DB API. This would apply only to the select, update, delete methods and not to the query method or anything else that would accept a raw SQL statement.

    Here’s my thought on how to implement it. Add an autoPrefix property to the DBAPI class that would be set to true by default. Every method that is fed a table parameter would then add the prefix to the table name if it wasn’t already there (if autoPrefix was set to true of course).

    That way it could be easily turned on or off and if we check if the prefix alread exstis we shouldn’t have much of a problem with backwards compatability?

    What do you think?
      • 25663 MODX Staff
      • 12,272 Posts
      I think it sounds pretty cool...
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 22303 MODX Staff
        • 10,725 Posts
        I think this would require an optional parameter in the methods, otherwise, how would I find tables without the prefix? It seems just as easy to me to say $modx->getFullTableName(’site_content’) as the table param in the method call.
          • 1764
          • 680 Posts
          Quote from: OpenGeek at Jan 30, 2006, 01:57 PM

          I think this would require an optional parameter in the methods, otherwise, how would I find tables without the prefix? It seems just as easy to me to say $modx->getFullTableName(’site_content’) as the table param in the method call.

          I agree that having to give an autoPrefix parameter in each method call isn’t much better than using getFullTableName but that’s why I thougt it would be good as a object property. I’m thinking that about 99% of the time you’re gotta want to have a prefix with your table names so I’m much more concerned with making it easy to include prefixes than to exclude them. Buf it you did want to exclude them you should be able to just set the property

          $db = new DBAPI();
          $db->autoPrefix = false;
          $db->select('*','my_table');
          


          The table prefix is a constant value that virtually never changes and it seems crazy that I have to deal with it in almost every bit of code I write. It’s not a huge inconvenience of course, but if we could make it one less hoop to jump through it would be nice.

          Honestly, I don’t like the getFullTableName method much because you have to call it for every table you use. I’d rater set a $prefix variable and be able to reuse it.

          Obviously this is not a huge deal. I just thought it would save a bit of time and hassle and I’m happy to keep things the way they are if there are any doubts about this.