From: Rob Church Date: Sat, 14 Jan 2006 01:45:14 +0000 (+0000) Subject: * Fixed installer bugs 921 and 3914 (issues with using root and so forth) X-Git-Tag: 1.6.0~566 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=10bbace106fa463c8a569b16e5f2fe01b1d35b2f;p=lhc%2Fweb%2Fwiklou.git * Fixed installer bugs 921 and 3914 (issues with using root and so forth) --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 306f09cb32..10565df38d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -482,6 +482,7 @@ fully support the editing toolbar, but was found to be too confusing. * Linker::formatComment corrupted the passed title object on PHP 5 if the comment included a section link. Use clone() to make a safe copy. * Add wfClone() wrapper since we're still using PHP 4 on some servers. +* Fixed installer bugs 921 and 3914 (issues with using root and so forth) === Caveats === diff --git a/config/index.php b/config/index.php index 12c38ba24c..b4bed7636a 100644 --- a/config/index.php +++ b/config/index.php @@ -502,60 +502,69 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { >http://dev.mysql.com/doc/mysql/en/old-client.html for help.\n"; } $dbc = new $dbclass; - if ($conf->DBtype == 'mysql') { - print "
  • Trying to connect to database server on $wgDBserver as root...\n"; - $wgDatabase = $dbc->newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 ); - + + # Attempt to connect with the specific credentials *first* + # This is a quick fix to bug 921 ("Install script always attempts to connect to database as root") + + if( $conf->DBtype == 'mysql' ) { + $ok = true; # Let's be optimistic + echo( "
  • Attempting to connect to database server..." ); + $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 ); if( $wgDatabase->isOpen() ) { - $myver = get_db_version(); - $wgDatabase->ignoreErrors(true); - $conf->Root = true; - print "
  • \n"; + # Whee, we're in + $conf->Root = false; + $wgDBadminuser = $wgDBuser; + $wgDBadminpassword = $wgDBpassword; + echo( "success. Connected as $wgDBuser.\n" ); } else { - print ""; - $ok = false; - switch( $err ) { - case 1045: - case 2000: - if( $conf->Root ) { - $errs["RootPW"] = "Check password"; - } else { - print "
  • Trying regular user...\n"; - /* Try the regular user... */ - $wgDBadminuser = $wgDBuser; - $wgDBadminpassword = $wgDBpassword; - /* Wait one second for connection rate limiting, present on some systems */ - sleep(1); - $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 ); - if( !$wgDatabase->isOpen() ) { - print "
  • "; + # Right, work out what's up + $errno = mysql_errno(); + $errtx = htmlspecialchars( mysql_error() ); + switch( $errno ) { + case 2002: + case 2003: + # Connection to server failed + $ok = false; + echo( "failed with error [$errno] $errtx.\n" ); + $errs["DBserver"] = "Connection failed"; + break; + case 1045: + case 2000: + # Authentication error, attempt to use root + sleep( 1 ); # Rate limiting + $wgDatabase = $dbc->newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 ); + if( $wgDatabase->isOpen() ) { + # Whee, fixed + $conf->Root = true; + echo( "success. Connected as root.\n" ); + } else { + # That didn't work either + $ok = false; + echo( "failed due to authentication errors. Check passwords." ); $errs["DBuser"] = "Check name/pass"; $errs["DBpassword"] = "or enter root"; $errs["DBpassword2"] = "password below"; $errs["RootPW"] = "Got root?"; - } else { - $myver = mysql_get_server_info( $wgDatabase->mConn ); - $wgDatabase->ignoreErrors(true); - $conf->Root = false; - $conf->RootPW = ""; - print " ok.\n"; - # And keep going... - $ok = true; } break; - } - case 2002: - case 2003: - $errs["DBserver"] = "Connection failed"; - break; - default: - $errs["DBserver"] = "Couldn't connect to database"; - break; - } - if( !$ok ) continue; + default: + # Something vicious and undocumented happened + # Panic and run our little installer ass off + $ok = false; + echo( "failed with error [$errno] $errtx.\n" ); + $errs["DBserver"] = "Couldn't connect to database"; + break; + } # switch + } # norm. conn. attempt + + if( $ok ) { + # Set the version info. and ignore errors + $wgDatabase->ignoreErrors( true ); + $myver = mysql_get_server_info( $wgDatabase->mConn ); + } else { + continue; } + } else /* not mysql */ { print "
  • Connecting to SQL server..."; $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);