diff --git a/core/lib/Thelia/Install/CheckDatabaseConnection.php b/core/lib/Thelia/Install/CheckDatabaseConnection.php index 50c117d22..a2a18853e 100644 --- a/core/lib/Thelia/Install/CheckDatabaseConnection.php +++ b/core/lib/Thelia/Install/CheckDatabaseConnection.php @@ -62,6 +62,11 @@ class CheckDatabaseConnection extends BaseInstall /** @var int Database port information */ protected $port = null; + /** + * @var \PDO instance + */ + protected $connection = null; + /** * Constructor * @@ -90,11 +95,28 @@ class CheckDatabaseConnection extends BaseInstall */ public function exec() { - $link = mysql_connect($this->host . ':' . $this->port, $this->user, $this->password); - if (!$link) { - throw new InstallException('Can\'t connect to the given credentials'); + + $dsn = "mysql:host=%s"; + + try { + $this->connection = new \PDO( + sprintf($dsn, $this->host), + $this->user, + $this->password + ); + } catch (\PDOException $e) { + + $this->validationMessages = 'Wrong connection information'; + + $this->isValid = false; } - mysql_close($link); + + return $this->isValid; + } + + public function getConnection() + { + return $this->connection; } } diff --git a/web/install/bdd.php b/web/install/bdd.php new file mode 100644 index 000000000..059a25eb8 --- /dev/null +++ b/web/install/bdd.php @@ -0,0 +1,113 @@ +. */ +/* */ +/*************************************************************************************/ + +$step=4; +include("header.php"); + +if (isset($_POST['host']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['port'])){ + + $_SESSION['install']['host'] = $_POST['host']; + $_SESSION['install']['username'] = $_POST['username']; + $_SESSION['install']['password'] = $_POST['password']; + $_SESSION['install']['port'] = $_POST['port']; + + $checkConnection = new \Thelia\Install\CheckDatabaseConnection($_POST['host'], $_POST['username'], $_POST['password'], $_POST['port']); + if(! $checkConnection->exec() || $checkConnection->getConnection()->query('show databases') === false){ + header('location: connection.php?err=1'); + exit; + } +} +elseif($_SESSION['install']['step'] >=3) { + + $checkConnection = new \Thelia\Install\CheckDatabaseConnection($_SESSION['install']['host'], $_SESSION['install']['username'], $_SESSION['install']['password'], $_SESSION['install']['port']); +} +else { + header('location: connection.php?err=1'); + exit; +} +$_SESSION['install']['step'] = 4; +$connection = $checkConnection->getConnection(); + +$databases = $connection->query('show databases'); +?> +