We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17187
    • 5 Posts
    Hello,

    If the database for my modx-cms is currently unavailable is it possible to show the user a simple html-page instead of the bad and not at all user-friendly php-error -message?
    If yes how do I do this?

    Any help is greatly appreciated!

      • 26903
      • 1,336 Posts
      You could just simply replace your index.php file in your top level install directory with a bit of HTML saying your site is down. Rename the original so you can replace it again when your DB comes back.
        Use MODx, or the cat gets it!
        • 17187
        • 5 Posts
        Thank you for the answer!

        I could do that but then I have to always check to see if my database is up and running and if it’s not I have to be real fast changing the code to prevent visitors to see the wrong thing. So unfortunatley that is not an option.
        I want it to be automatic.
        I know I could go in and tweak the code that generates the error-messages. But that feels a bit over the top.
        I thought the problem could be solved within the administration or perhaps by adding a module to the system. I mean these kind of error-messages are only useful when the site is under development. Once it’s up and running ’live’ these error-messages should all be replaced by something more user-friendly.
          • 26903
          • 1,336 Posts
          OK, if your database is going to be up or down as you say then MODx can’t really help you here, nor can anything else. You need a service provider that keeps your database up all the time, or one that helps you here somehow when it’s down. I would pursue this with them initially.
            Use MODx, or the cat gets it!
            • 17187
            • 5 Posts
            Hi, I appreciate the answers!
            So ok, I’m not asking for help with my database or anything. The only thing I would like to do is change the error-message. I don’t see why this should be impossible.
            I have been looking into some of the files which to me seems to output some sort of table with the errors. If I could simply replace this table with something else it would be great.
            I tried a bit with a file named message.quit.inc.php. But it didn’t do the trick. I’m sorry for going in and messing with the core-files but I really need to fix this for various reasons.
            Please help.
              • 26903
              • 1,336 Posts
              OK, in the file /manager/incldes/extenders/dbapi.mysql.class.inc.php is a function nmed connect, look for a line starting with ’if (!$this->conn’, this is line 89 in my 0.9.6.3 install, directly under this is a line that starts with ’$modx->messageQuit’, this is the function that generates the error table. You can simply replace this with your own function, or just comment this out and echo some simple HTML to say your site is down.

              As far as I know you can’t override this behavior in evo, nor can it be disabled without hacking the core somewhere.
                Use MODx, or the cat gets it!
                • 17187
                • 5 Posts
                Thanks!
                I have been trying this but it doesn’t affect my error-message at all (tried both my own function and a simple echo-message).
                It’s like it’s not enough. Do I need to dig deeper down somewhere?
                  • 26903
                  • 1,336 Posts
                  OK, we need to try the db connection before we hook in the php error handler, still comment out the message quit line in the connect function and echo your own HTML.

                  Then in the executeParser function of document.parser.class.inc.php move the ’this->db->connect();’ line(1031 in 0.9.6.1) from where it is to the top of the function, i.e make it the first line in the function, now if you fail to connect you will output your HTML and exit, if you do connect the error handler will be installed as normal and MODx will carry on Tried it here on test install, seems OK.
                    Use MODx, or the cat gets it!
                    • 17187
                    • 5 Posts
                    Yes! Finally..
                    Thank you so much for taking your time and helping me out with this problem.
                      • 26903
                      • 1,336 Posts
                      No probs, glad its sorted for you.
                        Use MODx, or the cat gets it!