We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24222
    • 63 Posts
    Hi,
    how can i store external db data into a tv that i can use from manager like a drop down menu?

    I use this code into a tv:
    @EVAL return include(getcwd().'/myselect.php');

    This is the code inside the included file:
    $myconn = mysql_pconnect($host,$dbname,$password);
    $database = mysql_select_db($mydb,$myconn);
    $query = "SELECT * FROM macchine";
    $result = mysql_query($query);
    $html = "";
    while ($row = mysql_fetch_array($result)) {
        $html .= $row['modello']."==".$row['idMacchina']."||";
    }
    return substr($html,0,-2);
    

    This code return a javascript alert with this message: "Logging error: couldn’t save log to table".

    How can i manage an external db? Thanks grin
      • 27226
      • 186 Posts
      Why don’t you use @SELECT instead?
      http://modxcms.com/select-binding.html
        • 11975
        • 2,542 Posts
        I’ve used something similar for one of my project

        @SELECT modello, idMacchina FROM macchine ORDER by idMacchina ASC

        the only issue is that I could not have an empty default value

        :-)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 24222
          • 63 Posts
          Hi heliotrope,
          thanks for the reply...

          How can I tell to modx that I refer to an external db?
          When I perform a select like this
          @SELECT modello, idMacchina FROM macchine ORDER by idMacchina ASC
          what’s the active connection and the selected db?
          How can I change this parameters?
          I don’t want to use a table in modx db...



            • 11975
            • 2,542 Posts
            Ok, I’m wrong grin I’ve readen too fast your post embarrassed
            I thought you were talking about modx_db

            I presume that @SELECT is bounded to an internal use.

            I hope someone will be able to answer you more accurately.


            :-)
              Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: quimo at Sep 01, 2006, 12:26 PM

              I use this code into a tv:
              @EVAL return include(getcwd().'/myselect.php');

              I don’t think getcwd() is going to work -- try something like this to make sure the script is being found. I think the failure of the EVAL binding to find the file is triggering some kind of error logging that is failing in the manager (ugh).
              @EVAL return include($modx->config['base_path'] . 'path/to/myselect.php');

                • 24222
                • 63 Posts
                I tried with your solution but the result in the same sad
                If I remove the first line (connect or pconnect) I have no javascript alert but the "mysql_query" statement failed...
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Try explicity closing your $myconn connection before your final return statement. I think the MODx dbapi is getting confused between its own connection and yours.
                    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
                    • 24222
                    • 63 Posts
                    I tried again with this code...
                    $myconn = mysql_pconnect($host,$usr,$passwd);
                    $database = mysql_select_db($db,$myconn);
                    $query = "SELECT * FROM macchine";
                    $result = mysql_query($query,$myconn);
                    while ($row = mysql_fetch_array($result)) {
                    $html .= $row['modello']."==".$row['idMacchina']."||";
                    }
                    mysql_close($myconn);
                    return substr($html,0,-2);
                    

                    ... but MODx always return the javascript alert sad
                    (the same behaviour using connect or pconnect)
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Hmm... I wonder if MODx is losing its connection altogether? Possibly your snippet needs to open a new connection to the cms database when you’re finished.
                        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