[*] IN : the installer can now attempt to create the database for you

This commit is contained in:
Damien Metzger
2013-07-03 11:04:34 +02:00
parent 92959311d9
commit bfa2f33c65
6 changed files with 380 additions and 313 deletions
+14 -1
View File
@@ -52,6 +52,18 @@ class DbMySQLiCore extends Db
return $this->link;
}
public static function createDatabase($host, $user, $password, $dbname)
{
if (strpos($host, ':') !== false)
{
list($host, $port) = explode(':', $host);
$link = @new mysqli($host, $this->user, $this->password, null, $port);
}
else
$link = @new mysqli($host, $user, $password);
return $link->query('CREATE DATABASE `'.bqSQL($dbname).'`');
}
/**
* @see DbCore::disconnect()
@@ -169,7 +181,8 @@ class DbMySQLiCore extends Db
if (!$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout))
return 1;
if (!$link->real_connect($server, $user, $pwd, $db))
// There is an @ because mysqli throw a warning when the database does not exists
if (!@$link->real_connect($server, $user, $pwd, $db))
return (mysqli_connect_errno() == 1049) ? 2 : 1;
$link->close();