0

I'm having some problems with a legacy program I'm starting back up. We had an image of this server, and the setup is Ubuntu 10.04, 5gb partition for mysql database, and 100gb filesystem. My issue is that every time this function that is supposed to create the connection to the database is called, it throws an error that the database is down.

static function createConnection($dbOptions = null)
    {
        $dsn = array(
            'phptype' => CATAPULT_DB_TYPE,
            'username' => CATAPULT_DB_USERNAME,
            'password' => CATAPULT_DB_PASSWORD,
            'hostspec' => CATAPULT_DB_HOST,
            'database' => CATAPULT_DB_DATABASE
            );

        $options = array();
        if ($dbOptions != null)
        {
            if (array_key_exists('username', $dbOptions))
            {
                $dsn['username'] = $dbOptions['username'];
            }

            if (array_key_exists('password', $dbOptions))
            {
                $dsn['password'] = $dbOptions['password'];
            }

            if (array_key_exists('host', $dbOptions))
            {
                $dsn['hostspec'] = $dbOptions['hostspec'];
            }

            if (array_key_exists('database', $dbOptions))
            {
                $dsn['database'] = $dbOptions['database'];
            }

            if (array_key_exists('persistent', $dbOptions))
            {
                if ($dbOptions['persistent'])
                {
                    $options['persistent'] = $dbOptions['persistent'];
                }
            }

            if (array_key_exists('debug', $dbOptions))
            {
                $options['debug'] = $dbOptions;
            }

            if (array_key_exists('portability',$dbOptions))
            {
                $options['portability'] = $dbOptions;
            }
        }
        else
        {
            $options['debug'] = 0;
            $options['portability'] = MDB2_PORTABILITY_ALL;
        }


        // uses MDB2::factory() to create the instance
        // and also attempts to connect to the host
        //
        // for some reason I was using connect rather than singleton... not sure why that was
        // this was creating many duplicate database connections when I was dealing with transactions
        //$mdb2 = MDB2::connect($dsn, $options);
        $mdb2 = MDB2::singleton($dsn, $options);

        if (PEAR::isError($mdb2))
        {
            $logger = Logger::getFileLogger('dbConnect.php:createConnection');

            // setup email configuration
            $conf = array('subject' => 'CRITICAL ERROR: SYSTEM DATABASE CONNECTION LOST');
            $loggerEmail = Logger::getEmailLogger('dbConnect.php:createConnection');

            // error's here should not only be logged but emailed as well

            // TODO: log the error
            $log_message = "Failed to connect to database, verify connection settings.";
            if ($mdb2 != null)
            {
                $log_message .= ' Additional info:  -- ' . $mdb2->getMessage();
            }

            $logger->log($log_message);
            $loggerEmail->log($log_message);

            return (NULL);
        }
        else
        {
            return ($mdb2);
        }

Once again, this is legacy code, and I'm not really a database guy, but I have checked the privileges on the user, and it says GRANT ALL PRIVILEGES ON 'dbName'.* TO 'user'@'localhost'

Output of /var/log/apache2/error.log

sh: /usr/sbin/sendmail: not found

it repeats that over and over 52 times.

Any ideas on troubleshooting?

  • Think this should be moved to stack overflow as it's looking like a programmatic error? – sgtbeano Nov 13 '13 at 16:43
  • Start the database server? Find the developer and strangle him for not finishing the error handling code? – Michael Hampton Nov 13 '13 at 16:46
  • @MichaelHampton database is started, I'll work on the second part :) – trueCamelType Nov 13 '13 at 18:41
  • @sgtbeano I thought about that, but I'm not certain it is a programming error. I thought it was possibly a settings error at first, but I put the code in just in case somebody saw something abnormal. I can't be sure which it is yet. – trueCamelType Nov 13 '13 at 18:42
0

Try connecting via the command line to see if it's a PHP issue or a MySQL issue:

mysql -u USERNAME -pPASSWORD -h 127.0.0.1 DBNAME
| improve this answer | |
  • I was able to connect successfully via the command line. Could there be permission problems with the php file connecting to the database possibly? I didn't think so, and the permissions look good, but the code looks good as well (to me). – trueCamelType Nov 13 '13 at 8:25
  • Can you edit your question to show all errors? Anything that is output on the screen. Anything in apache error log /var/log/apache2/error.log try var_dump'ing $mdb2 = MDB2::singleton($dsn, $options); – jessh Nov 13 '13 at 11:40
  • 1
    That may have answered my question right there. I wasn't aware that error log was there, thanks. I'll edit the question with the output of that, and keep trying to figure it out on my own also. Thanks – trueCamelType Nov 13 '13 at 16:33
0

If you look at your php.ini file, I think you'll find it's configured to email you errors; but it's failing to do that (which would explain both why you don't see any useful errors, and why you're getting that sendmail error message).

I suggest at least temporarily reconfiguring that file to write to an error log somewhere, that you can look through. Just guessing by what you posted here, there are only a few configuration options, so once you know the error, it should be easy to solve. Since you can connect locally I'm guessing you'll end up fixing a misconfiguration in the applicaiton config file, wherever that is.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.