Fixed bug #5941: Log reason of failure on DB connect
authorMartin Kutschker <martin.t.kutschker@blackbox.net>
Mon, 6 Aug 2007 19:29:49 +0000 (19:29 +0000)
committerMartin Kutschker <martin.t.kutschker@blackbox.net>
Mon, 6 Aug 2007 19:29:49 +0000 (19:29 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2440 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_db.php

index 44afe94..b9057b8 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+
+2007-08-06  Martin Kutschker  <martin.t.kutschker@blackbox.net>
+
+       * Fixed bug #5941: Log reason of failure on DB connect
+
 2007-08-06  Ernesto Baschny  <ernst@cron-it.de
 
        * Fixed bug #6017: Better transliteration for hebrew (lower-cased latin letters)
index 9a89c06..09d3f23 100755 (executable)
@@ -884,14 +884,21 @@ class t3lib_DB {
         * @return      pointer         Returns a positive MySQL persistent link identifier on success, or FALSE on error.
         */
        function sql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password)   {
+                       // mysql_error() is tied to an established connection
+                       // if the connection fails we need a different method to get the error message
+               ini_set('track_errors', 1);
+               ini_set('html_errors', 0);
                if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect'])  {
                        $this->link = @mysql_connect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password);
                } else {
                        $this->link = @mysql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password);
                }
+               $error_msg = $php_errormsg;
+               ini_restore('track_errors');
+               ini_restore('html_errors');
 
                if (!$this->link) {
-                       t3lib_div::sysLog('Could not connect to Mysql server '.$TYPO3_db_host.' with user '.$TYPO3_db_username.'.','Core',4);
+                       t3lib_div::sysLog('Could not connect to Mysql server '.$TYPO3_db_host.' with user '.$TYPO3_db_username.': '.$error_msg,'Core',4);
                } else {
                        $setDBinit = t3lib_div::trimExplode(chr(10), $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'],TRUE);
                        foreach ($setDBinit as $v)      {
@@ -900,6 +907,7 @@ class t3lib_DB {
                                }
                        }
                }
+
                return $this->link;
        }