We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    You can use the MODx DBAPI for this

    DBAPI only operates on the MODx database, though, right? In my particular case, I had changed loopdbchunk to deal with an external database. So in that case, I think he’d need to stick with the SQL querys you first mentioned.

    Unless, of course, I don’t understand how to use DBAPI, which is entirely possible smiley
    MattC
      • 24673
      • 3 Posts
      Thanks Susan and MattC, I was able to accomplish what I wanted by combining the tips
      that both of you gave me.

      I just had to put this in my details page:

      ------------------------------

      [!loopDbChunk?
      &chunkName=`DBtestingdetails`
      &sql=`select * from my_db.my_table where mycollumn_name _eq_ ’[[snippetexamplebymatt]]’`
      &perPage=`1`
      &missingValTxt=`Pending`
      !]

      -----------------------------------

      Is this secure?


      Matt, when you say external database you mean that its located in another server or that it isnt
      a table in the modx database? in my case its another database in the same server(localhost).

      Suzan, I tried to load my db using one of the examples given in the wiki but it seems that modx
      isnt able to locate it because it adds a modx prefix, it appears like this in the error: modx.my_db.my_table

      Another tip I saw in the forums was to change the index.php?id=94 to [~94~] this
      make it easier for friendly urls.
        • 18913
        • 654 Posts
        Hi,
        In my use of the altered loopdbchunk, I am querying a non-MODx database on the same server. (At least I think it’s on the same server.) But it is a completely different database than the one MODx uses, as I want to keep website material and event data separate.

        But to do that I had to modify loopdbchunk - see message #46 above - to use reqular php sql calls rather than what is built in to MODx. I seem to recall looking at the MODx query API and thinking that technically one could tell it to connect to another database, do a query and then reconnect to the MODx database. But I thought that might risk breaking something, so I just replaced the code to create what is in effect a "loopexdbchunk" (Loop External Database Chunk) routine.

        Hope that helps,
        MattC
          • 10450
          • 30 Posts
          hey thr how can i connect to my external database in same server. I have dbedit module
            • 18913
            • 654 Posts
            I played around with dbedit for a little while, but ended up using loopdbchunk. In both instances, I changed all the modx-specific database calls (e.g $modx->db) to their equivalent mysql calls. Then you need to add a few lines of code at the start to open the database, and a few at the end to close the database.
            MattC
              • 10450
              • 30 Posts
              Quote from: mconsidine at Jan 29, 2010, 07:16 AM

              I played around with dbedit for a little while, but ended up using loopdbchunk. In both instances, I changed all the modx-specific database calls (e.g $modx->db) to their equivalent mysql calls. Then you need to add a few lines of code at the start to open the database, and a few at the end to close the database.
              MattC

              Thanks,

              Can u give me some example?
                • 18913
                • 654 Posts
                See posts earlier in thread.
                MattC
                  • 6513
                  • 28 Posts
                  Hello all,
                  I use loopdbchunk all over the place, it would have taken me months ot do it myself smiley
                  I looked through the posts here but couldn’t find anyone trying the same thing.

                  I am trying to figure out if I can determine if the current page is the last page to determine which chunks to display in the sidebar of the page. The last page isn’t always the same length and I don’t want to have empty space in the middle of the page if the content in the sidebar is taller.

                  As my php skills are barely beginner I am nor sure if I can do this. Any help is greatly appreciated smiley
                    • 28972
                    • 19 Posts
                    How to put WHERE [field_name]= getUserLogin() in loopDbChunk query?

                    $query = 'SELECT ' . $fields . ' FROM ' . $this->tableName
                      • 28972
                      • 19 Posts
                      ok i create this code
                      $query = 'SELECT ' . $fields . ' FROM ' . $this->tableName . " WHERE `uid` = '" . $modx->getLoginUserID() . "'";


                      This shows the page but don’t shows the selected data.