Connect($db_hostname,$db_username,$db_password))
{
$db_server_status = true;
if($db_type=='mysql')
{
$mysql_conn = mysql_connect($db_hostname,$db_username,$db_password);
$version = explode('-',mysql_get_server_info($mysql_conn));
$mysql_server_version=$version[0];
mysql_close($mysql_conn);
}
if(isset($_REQUEST['check_createdb']) && $_REQUEST['check_createdb'] == 'on')
{
$root_user = $_REQUEST['root_user'];
$root_password = $_REQUEST['root_password'];
// drop the current database if it exists
$dropdb_conn = &NewADOConnection($db_type);
if(@$dropdb_conn->Connect($db_hostname, $root_user, $root_password, $db_name))
{
$query = "drop database ".$db_name;
$dropdb_conn->Execute($query);
$dropdb_conn->Close();
}
// create the new database
$db_creation_failed = true;
$createdb_conn = &NewADOConnection($db_type);
if(@$createdb_conn->Connect($db_hostname, $root_user, $root_password)) {
$query = "create database ".$db_name;
// TODO: MySQL version less than 4.1.2 does not suppot UTF-8, a check here is required for it.
if($create_utf8_db == 'true') {
if($db_type=='mysql')
$query .= " default character set utf8 default collate utf8_general_ci";
$db_utf8_support = true;
}
if($createdb_conn->Execute($query)) {
$db_creation_failed = false;
}
$createdb_conn->Close();
}
}
// test the connection to the database
if(@$conn->Connect($db_hostname, $db_username, $db_password, $db_name))
{
$db_exist_status = true;
if(!$db_utf8_support) {
// Check if the database that we are going to use supports UTF-8
$db_utf8_support = check_db_utf8_support($conn);
}
}
$conn->Close();
}
}
// Update vtiger charset to use
$vt_charset = ($db_utf8_support)? "UTF-8" : "ISO-8859-1";
$error_msg = '';
$error_msg_info = '';
if(!$db_type_status || !$db_server_status)
{
$error_msg = 'Unable to connect to database Server. Invalid mySQL Connection Parameters specified';
$error_msg_info = 'This may be due to the following reasons:
- specified database user, password, hostname, database type, or port is invalid. More Information
- specified database user does not have access to connect to the database server from the host';
}
elseif($db_type == 'mysql' && $mysql_server_version < '4.1')
{
$error_msg = 'MySQL version '.$mysql_server_version.' is not supported, kindly connect to MySQL 4.1.x or above';
}
elseif($db_creation_failed)
{
$error_msg = 'Unable to Create Database '.$db_name;
$error_msg_info = 'Message: The database User "'. $root_user .'" doesn\'t have permission to Create database. Try changing the Database settings';
}
elseif(!$db_exist_status)
{
$error_msg = 'The Database "'.$db_name.'" is not found.Try changing the Database settings';
}
else
{
$next = true;
}
// Write the necessary information to platform.log
require_once('include/logging.php');
$log =& LoggerManager::getLogger('PLATFORM');
$info_style_start = '