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

Your name:

Reply:


Posted by wayne on 08/25/05 03:01

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;
}
}
//==========================================================================//

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация