We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20999
    • 20 Posts
    I am trying to get PEAR templates working in MODx, and am not having much luck. PEAR works in MODx, but does load the template. My code works fine up until the last line of my code where I display the template:
    $template->show();
    I even tried:
    return $template->show();

    When I try to run the script that loads the template I get the error:
    "Error while inserting event log into database."

    I have PEAR HTML_Template_IT installed, and that obviously works because I can create a new templates, populate them and everything but display them. Does anyone have experience with this, or know what could be going on? I can provide more information, or my code if that is helpful to anyone. PEAR, PHP, MySQL, my paths, etc don’t seem to be causing the issue, so I think it is MODx not liking PEAR templates, but I could be wrong. Anyway, please help!

    Thanks!!!!
      • 20999
      • 20 Posts
      I guess I should clarify:

      My this is my snippet:
      <?php
      include_once($modx->config['base_path'].'assets/quoteForm/scripts/instruments.php');
      ?>
      


      This snippet is supposed to grab some form data, create a session array storing the information and then query the database to fill a PEAR HTML Template IT. I can put echo statements all over the place showing that my code is querying the database and that it is finding the template and loading the template just fine, then if I put a
      die("foo");
      right before the last line of my code which is
      $template->show();
      I can see all my echo’s, and see the info pulled from the database. If I remove the
      die("foo");
      statement and let my code finish (showing the template), the error I get is: "Error while inserting event log into database.". Just for kicks, and because I was curious to see what would happen, I changed the path of the template to a path that had no templates (.tpl files) in it. I changed my code from the correct path:
      $template = new HTML_Template_IT("assets/quoteForm/templates");

      to:
      $template = new HTML_Template_IT("assets/quoteForm/scripts");


      and then I get a new error message:

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

      PHP error debug
      Error: fopen(assets/quoteForm/scripts/instruments.tpl) [function.fopen]: failed to open stream: No such file or directory
      Error type/ Nr.: Warning - 2
      File: /usr/local/share/pear/HTML/Template/IT.php
      Line: 914
      Line 914 source: if (!($fh = @fopen($filename, ’r’))) {

      Parser timing
      MySQL: 0.0036 s (2 Requests)
      PHP: 0.0855 s
      Total: 0.0891 s
      Error while inserting event log into database.

      ...but notice I get at the very end of that error "Error while inserting event log into database." again. There should not really be a problem I wouldn’t think because I a snippet that calls a PHP script which performs a query on a database, and then populates a template which is just HTML with a few HTML comments and markers ({FOO} and {BAR}) to tell PEAR where to populate. PEAR has horrible documentation, and support online, so I posted this there too, but I am not expecting much help there.

      I’m still going at it, but if anyone has thoughts or suggestions, that would be very much appreciated.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        The parser is trying to insert a message into the event log, and can’t for some reason or another. Have you emptied the event log lately? If it gets too full, the next ID will be bigger than the field definition allows for. As to what it’s trying to report, that’s another matter. Most likely an error condition of some kind.
          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
          • 20999
          • 20 Posts
          I haven’t emptied the event log recently, no. The install on the server I am using is just two weeks old and I am the only person who has access to access this server. Ill give that a try when I get to work tomorrow. Hopefully either this will work, or I will find some useful info in the event log. MODx’s event log is just a text file in the MODx directory, or is in the MODx database? sorry, I am still learning the ropes of MODx.
            • 20999
            • 20 Posts
            So I cleared the log... there turned out to be 42 entires in there. That however appears not to be the problem. I made an interesting observation this morning, when trying to debug this.

            I commented out all my code so I just had this:
            <?php
                    require_once "HTML/Template/IT.php";
                    include "functions.php";
                    $formConnect = connectAndSelect();
                    echo "test";
            ?>
            

            and this caused the error that I have been getting "Error while inserting event log into database."

            The HTML/Template/IT.php is the PEAR template php file, and the functions.php is my function file. connectAndSelect() connects or and selects the database, and includes a file that stores the username, password, etc, and returns the connection. I don’t know what is going on! 6 lines of code including 2 includes/requires should not be causing this!!!!
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: nathan at Aug 08, 2007, 01:18 PM

              The HTML/Template/IT.php is the PEAR template php file, and the functions.php is my function file. connectAndSelect() connects or and selects the database, and includes a file that stores the username, password, etc, and returns the connection. I don’t know what is going on! 6 lines of code including 2 includes/requires should not be causing this!!!!

              If connectAndSelect() is hijacking the mysql connection as I suspect, then MODx is unable to see it’s data any longer once that function is executed, which would explain the error...
                • 20999
                • 20 Posts
                Right. That makes sense: When I open another mysql connection in connectAndSelect(), it "overrides" MODx’s database connection. I figured I could just close the connection I opened when I was done with it, using mysql_close, but then I get this error:

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

                PHP error debug
                Error: mysql_query() [function.mysql-query]: Access denied for user ’root’@’localhost’ (using password: NO)
                Error type/ Nr.: Warning - 2
                File: /usr/local/www/apache22/data/manager/includes/document.parser.class.inc.php
                Line: 1292
                Line 1292 source: $ds= @mysql_query($sql);

                Parser timing
                MySQL: 0.0036 s (2 Requests)
                PHP: 0.0908 s
                Total: 0.0944 s
                Error while inserting event log into database.

                Is there a way around this? I guess I could just put the tables I am using from a separate database, but I want to keep MODx and its data separate from the data collected from this form on the web.
                  • 20999
                  • 20 Posts
                  So i figured out a temporary fix. In manager/includes/document.parser.class.inc.php, in the log event function, I opened a new database connection to the MODx database. Anyone have suggestions on how to fix this? I know mysql_connect can take a connection parameter, but I don’t know what the MODx connection would be called, or how to access it. Does that even make sense?
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: nathan at Aug 09, 2007, 03:55 PM

                    So i figured out a temporary fix. In manager/includes/document.parser.class.inc.php, in the log event function, I opened a new database connection to the MODx database. Anyone have suggestions on how to fix this? I know mysql_connect can take a connection parameter, but I don’t know what the MODx connection would be called, or how to access it. Does that even make sense?

                    The only real fix is to use something that does not hijack existing mysql connections. The folks that maintain the PEAR code you are using need to address that if it is to be used as a library within another framework.