We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    Hi, I’m having a problem with a snippet. I wrote up some code to extract some posts from my forum to display them on my homepage. It worked without MODx, but I put that same code as a snippet and now I’m getting parsing errors.

    I believe it’s because I’m selecting a different DB than what modx was installed to, and I was wondering what I should to to do about resolving this issue. Thanks alot!
      • 33337
      • 3,975 Posts
      Can you please provide details of error ?

      thanks.

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 34162
        • 1 Posts
        Sure.

        PHP error debug
        Error: mysql_result(): supplied argument is not a valid MySQL result resource
        Error type/ Nr.: Warning - 2
        File: /www/z/zeroinfinity2/htdocs/manager/includes/document.parser.class.inc.php(667) : eval()’d code
        Line: 131


        Like I said though.. the script connects to a different database.. Maybe that’s it?
          • 33337
          • 3,975 Posts
          Something in your code is a problem, how about sharing a code ? smiley

          regards,

          zi
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            There are some functions in the parser class for accessing an external database. You’ll need to scan through the parser class file to find them, though. They aren’t part of the MODx DBAPI.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 22303 MODX Staff
              • 10,725 Posts
              Actually, to use the DBAPI to connect to a different DB, all you do is this:

              $mydb= new DBAPI();
              $mydb->connect($host='mysql.mydomain.tld',$dbase='mydbname', $uid='mydbuser',$pwd='mydbpwd');
              


              NOTE: The $param=’value’ syntax was just an example so I could describe the variables being passed, you only have to include a var or the value directly.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Thanks, Jason. That is much better! This fairly obvious advantage of a class structure went right past me.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 34162
                  • 1 Posts
                  Okay, I’ll try that and tell you how it goes. Thanks for your quick replies so far! grin


                  EDIT: I got it working! Thanks alot everyone! grin
                  (It was the connection to the database... plus the way I was handling the date and time.)
                    • 33337
                    • 3,975 Posts
                    hi Zacarias !

                    We are glad to know that your problem is solved.

                    regards,

                    zi
                      Zaigham R - MODX Professional | Skype | Email | Twitter

                      Digging the interwebs for #MODX gems and bringing it to you. modx.link