We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4971
    • 964 Posts
    I need to turn this code:

    <?php
    require_once('/home2/domain/public_html/clients/include-locations.inc');
    require_once($include_directory . 'vars.php');
    require_once($include_directory . 'adodb/adodb.inc.php');
    require_once($include_directory . 'utils-interface.php');
    $con = &adonewconnection($xrms_db_dbtype);
    $con->connect($xrms_db_server, $xrms_db_username, $xrms_db_password, $xrms_db_dbname);
    $con->debug = 1;
    ?>


    into a snippet so I can then run this code in my contact form:

    <?php
    $sql = "SELECT company_source_id,company_source_pretty_name FROM company_sources WHERE company_source_record_status ='a' ORDER BY company_source_pretty_name";
    $rst = $con->execute($sql);
    while (!$rst->EOF) {
      $output .= "<option value=".$rst->fields['company_source_id'].">".$rst->fields['company_source_pretty_name']."</option>\n";
      $rst->movenext();
    }
    $rst->close();
    return $output;
    ?>


    in my page...

    the problem is that the parser is not including the files...  it does not complain about
    require_once('/home2/domain/public_html/clients/include-locations.inc');
    require_once($include_directory . 'vars.php');
    but then it indicates that adodb/adodb.inc.php is not in the directory because the variable $include_directory does not contain anything!!! and the variable is defined in the first
    require....

    what is going on?
    what error am I making in the snippet?

    thanks in advance...

    Carlos
      Website: www.mercologia.com
      MODX Revo Tutorials:  www.modxperience.com

      MODX Professional Partner
      • 3749
      • 24,544 Posts
      Just a wild guess, but I’d say $include_directory is empty. The first require_once works because it doesn’t use it, the second works because vars.php is in the same directory as the script, and the third fails because it really needs the directory prefix.

      Put this right after the first line to see if I’m right:

      echo ’Include_directory: ’ . $include_directory . ’---
      ’;

      BTW, I think there might be a much easier way to get the data in MODx. See if this might work for you: http://wiki.modxcms.com/index.php/Access_another_database_from_MODx

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 4971
        • 964 Posts
        Thanks Bob, that is exactly what I thought at the beginning but the first two files are included (require_once) corrrectly at
        and all the variables ($include_directory and all the db variables from vars.php) are OK.

        The file adodb/adodb.inc.php is in the correct directory. I even changed the permissions to 0777 but no luck.
        The error I get is the following...


        « MODx Parse Error »
        MODx encountered the following error while attempting to parse the requested resource:
        « PHP Parse Error »

        PHP error debug
        Error: require_once(adodb/adodb.inc.php) [function.require-once]: failed to open stream: No such file or directory
        Error type/ Nr.: Warning - 2
        File: /home2/project/public_html/modx/manager/includes/document.parser.class.inc.php(769) : eval()’d code
        Line: 6

        Parser timing
        MySQL: 0.0034 s (10 Requests)
        PHP: 0.0316 s
        Total: 0.0350 s

        any other clues?

        Thanks for the tip on the wiki how to... but I would like to make this work using the XRMS API first...
        it is supposed to be faster .... hahaha...
          Website: www.mercologia.com
          MODX Revo Tutorials:  www.modxperience.com

          MODX Professional Partner
          • 3749
          • 24,544 Posts
          This error message means that the $include_directory variable must be empty:

          Error:    require_once(adodb/adodb.inc.php) [function.require-once]: failed to open stream: No such file or directory    


          Otherwise, it would show the $include_directory in the require_once call in the error message.

          It would seem that either $include_directory is misspelled somewhere or it’s set to "" in one of the previously included files (maybe an = instead of == somewhere?), or it’s missing from the include-locations.inc file.

          You can try setting $include_directory explicitly just before the failing require_once call for starters.

          That’s all I’ve got.


            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 4971
            • 964 Posts
            OK... some small progress here...

            found a global declaration was clearing the $include_directory variable... now that part is working, but I am getting another error when including adodb/adodb.inc.php

            from the Reports->System Events log I am getting:

            xrmsLoad - Snippet - System Events
            Error

            Event Id: 1 Source: xrmsLoad - Snippet

            Date: 08-Oct-2008 03:46 AM User:


            Assigning the return value of new by reference is deprecated

            What does this mean?


            Edit: Thanks Bob, of course you were right!! smiley
              Website: www.mercologia.com
              MODX Revo Tutorials:  www.modxperience.com

              MODX Professional Partner
              • 3749
              • 24,544 Posts
              Some cursory googling suggests that your code would work in PHP4.

              This error report is generated when PHP5 is running in E_STRICT mode.

              To disable Strict Error Reporting, edit your php.ini file and set the error_reporting to:

              error_reporting  =  E_ALL & ~E_STRICT


              Or, (probably better) in your MODx .htaccess file in your root, you can add the following line:


              php_value error_reporting 6143

              Which is the bit value of E_ALL & ~E_STRICT.


              That said, it looks like the code should still work since it’s really only a warning so you may have other problems.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 4971
                • 964 Posts
                Bob, thanks a lot for your patience...

                at the end it worked using the DBAPI from modx that you suggested...
                the other way is more complicated... and it does not work!

                appreciate it a lot!

                Carlos
                  Website: www.mercologia.com
                  MODX Revo Tutorials:  www.modxperience.com

                  MODX Professional Partner
                  • 3749
                  • 24,544 Posts
                  I’m glad to hear it worked for you. I think the MODx db access will be at least as fast, if not faster.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting