static function connect()
{
$connection = self::connection();
$args = func_get_args();
$host = a::get($args, 0, c::get('db.host', 'localhost'));
$user = a::get($args, 1, c::get('db.user', 'root'));
$password = a::get($args, 2, c::get('db.password'));
$database = a::get($args, 3, c::get('db.name'));
$charset = a::get($args, 4, c::get('db.charset', 'utf8'));
// don't connect again if it's already done
$connection = !$connection ? @mysql_connect($host, $user, $password) : $connection;
// react on connection failures
if (!$connection) {
return self::error(l::get('db.errors.connect', 'Database connection failed'), true);
}
self::$connection = $connection;
// select the database
$database = self::database($database);
if (error($database)) {
return $database;
}
// set the right charset
$charset = self::charset($charset);
if (error($charset)) {
return $charset;
}
return $connection;
}