We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31037
    • 358 Posts
    EDIT: This is s stupid post, please don’t read it! My brain was on a break when writing it! wink

    To really learn MODx and PHP/MySql I’ve decided to create an add-on. For a newbie I think I managed pretty well so far! But now there are two MODx users waiting for my snippet, and everything takes me such a long time.

    So, sorry if this should be obvious, but I want to create a new table in the MODx database from within my snippet. For my other database interaction I’ve used the dbapi, but from what I can see there is nothing in the api that can help me here. EDIT: Me->Stupid tongue Of course there is!

    To speed up my development I would be grateful if someone could give me a hint with some code example. Or is there a snippet that does this kind of database handling that I could look into?

    I really try to find my own answers, but now I feel the pressure to at least be able to create a beta of my snippet, so please, help smiley
      • 22815
      • 1,097 Posts
      Good question.

      I’ve seen a couple of modules check for the existence of a table, and then create it if it doesn’t exist.

      For example, http://modxcms.com/Page-Hit-Counter-1.0-880.html claims to do this.

      I can’t think of a snippet off hand that has done this, but the principles are similar. Be sure to include the prefix.

      Personally, however, I’d prefer to just share the SQL that is necessary to create the table. (Dumping your database table structure to a file will give you the SQL you need).
      You could then suggest that people install and use http://modxcms.com/SQLquerry-1.0-984.html to run the SQL and create new table.
        No, I don't know what OpenGeek's saying half the time either.
        MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
        Forum: Where to post threads about add-ons | Forum Rules
        Like MODx? donate (and/or share your resources)
        Like me? See my Amazon wishlist
        MODx "Most Promising CMS" - so appropriate!
        • 31037
        • 358 Posts
        Thanks for your reply!

        I will not know the name of either the table or the columns needed to be created, and I want to make it really easy for the user, so I guess your second option will not work in my snippet. But I’ll sure have a look into the code of that module, and also check if your second option can be used with some modification.

        If not, I guess I’ll create a database manipulation snippet, will give me something to do for the comming month or so wink

        At my pace I’ll never release my snippet tongue But I learn a lot, and that’s not bad!

        Again, thanks!

        EDIT: Just looking at the code for 2.5 seconds solved it, I must be tiered today. I just need to use the... No, I just need to use my brain, it should have been obvious how to solve it, wasn’t even a problem! Thanks! laugh