explain to what's going with this piece of code.

From: Date: Thu, 25 Aug 2005 00:01:10 +0000
Subject: explain to what's going with this piece of code.
Groups: php.general 
Request: Send a blank email to php-general+get-221304@lists.php.net to get a copy of this message
When I run a script from a package I download, it always bombs out on this section. I think that its getting the wrong parameters when it tries to make the Connection. I use PostgreSQL as my DB.Moodle is the name of the database and the user is moodleuser. I do not have a password on this DB. //==========================================================================// /// Check database settings if stage 3 data submitted /// Try to connect to the database. If that fails then try to create the database if ($INSTALL['stage'] == 3) { print 'DO I GET HERE'; if (empty($INSTALL['dbname'])) { $INSTALL['dbname'] = 'moodle'; } /// different format for postgres7 by socket if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) { __________________________________________________________________ MY QUESTION This is the part I'm confuse on. Why does it set dbhost to the parameters for the Connect statements and then zero them out? ________________________________________________________________ $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'"; $INSTALL['dbuser'] = ''; $INSTALL['dbpass'] = ''; $INSTALL['dbname'] = ''; if ($INSTALL['prefix'] == '') { /// must have a prefix $INSTALL['prefix'] = 'mdl_'; } } if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present if (!extension_loaded('mysql')) { $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install'); $nextstage = 3; } } if (empty($errormsg)) { $db = &ADONewConnection($INSTALL['dbtype']); error_reporting(0); // Hide errors __________________________________________________________ MY QUESTION This is the other part I'm confuse on.At this point dbhost has the values from above and the call is passing them again. ___________________________________________________________ if (! $dbconnected = $db->Connect($INSTALL['dbhost'], $INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) { /// The following doesn't seem to work but we're working on it /// If you come up with a solution for creating a database in MySQL /// feel free to put it in and let us know if ($dbconnected = $db->Connect($INSTALL['dbhost'], $INSTALL['dbuser'],$INSTALL['dbpass'])) { switch ($INSTALL['dbtype']) { /// Try to create a database case 'mysql': if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) { $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'], $INSTALL['dbname']); } else { $errormsg = get_string('dbcreationerror', 'install'); $nextstage = 3; } break; } } } } error_reporting(7); if (($dbconnected === false) and (empty($errormsg)) ) { $errormsg = get_string('dbconnectionerror', 'install'); $nextstage = 3; } } //==========================================================================//

« previous php.general (#221304) next »