function db_start() { global $DatabaseServer, $DatabaseUsername, $DatabasePassword, $DatabaseName, $DatabasePort, $DatabaseType; switch ($DatabaseType) { case 'oracle': $connection = @ocilogon($DatabaseUsername, $DatabasePassword, $DatabaseServer); break; case 'postgres': //if($DatabaseServer!='localhost') //use for windows if ($DatabaseServer != 'host') { //updated for linux $connectstring = "host={$DatabaseServer} "; } if ($DatabasePort != '5432') { $connectstring .= "port={$DatabasePort} "; } $connectstring .= "dbname={$DatabaseName} user={$DatabaseUsername}"; if (!empty($DatabasePassword)) { $connectstring .= " password={$DatabasePassword}"; } $connection = pg_connect($connectstring); break; case 'mysql': $connection = mysql_connect($DatabaseServer, $DatabaseUsername, $DatabasePassword); mysql_select_db($DatabaseName); break; } // Error code for both. if ($connection === false) { switch ($DatabaseType) { case 'oracle': $errors = OciError(); $errormessage = $errors['message']; break; case 'postgres': $errormessage = pg_last_error($connection); break; case 'mysql': $errormessage = mysql_error($connection); break; } db_show_error("", "Could not Connect to Database: {$DatabaseServer}", $errstring); } return $connection; }
function db_start() { global $DatabaseServer, $DatabaseUsername, $DatabasePassword, $DatabaseName, $DatabasePort, $DatabaseType; switch ($DatabaseType) { case 'oracle': $connection = @ocilogon($DatabaseUsername, $DatabasePassword, $DatabaseServer); break; case 'postgres': if ($DatabaseServer != 'localhost') { $connectstring = "host={$DatabaseServer} "; } if ($DatabasePort != '5432') { $connectstring .= "port={$DatabasePort} "; } $connectstring .= "dbname={$DatabaseName} user={$DatabaseUsername}"; if (!empty($DatabasePassword)) { $connectstring .= " password={$DatabasePassword}"; } $connection = pg_connect($connectstring); break; case 'mysql': $connection = mysql_connect($DatabaseServer, $DatabaseUsername, $DatabasePassword); mysql_select_db($DatabaseName); break; } // Error code for both. if ($connection === false) { switch ($DatabaseType) { case 'oracle': $errors = OciError(); $errormessage = $errors['message']; break; case 'postgres': $errormessage = pg_last_error($connection); break; case 'mysql': $errormessage = mysql_error($connection); break; } // TRANSLATION: do NOT translate these since error messages need to stay in English for technical support db_show_error("", sprintf('Could not Connect to Database Server \'%s\'', $DatabaseServer), $errstring); } return $connection; }