From e38b3a9c1bf6b5dd6b9a39fa8947c4475923caf3 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 4 Jan 2014 14:34:01 +0100 Subject: Petits changements install --- app/sql.php | 2 +- p/i/install.php | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/sql.php b/app/sql.php index 5a28858a7..1b43da30a 100644 --- a/app/sql.php +++ b/app/sql.php @@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `%1$sentry` ( ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB; -INSERT INTO `%1$scategory` (name) VALUES(:catName); +INSERT IGNORE INTO `%1$scategory` (id, name) VALUES(1, :catName); '); define('SQL_DROP_TABLES', 'DROP TABLES %1$sentry, %1$sfeed, %1$scategory'); diff --git a/p/i/install.php b/p/i/install.php index 3316d222b..6891006fa 100644 --- a/p/i/install.php +++ b/p/i/install.php @@ -12,7 +12,7 @@ if (isset ($_GET['step'])) { define ('STEP', 1); } -define('SQL_CREATE_DB', 'CREATE DATABASE %1$s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;'); +define('SQL_CREATE_DB', 'CREATE DATABASE IF NOT EXISTS %1$s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;'); include(APP_PATH . '/sql.php'); @@ -556,12 +556,13 @@ function checkBD () { PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ); - // on ouvre une connexion juste pour créer la base si elle n'existe pas - $str = 'mysql:host=' . $_SESSION['bd_host'] . ';'; - $c = new PDO ($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options); - - $sql = sprintf (SQL_CREATE_DB, $_SESSION['bd_base']); - $res = $c->query ($sql); + try { // on ouvre une connexion juste pour créer la base si elle n'existe pas + $str = 'mysql:host=' . $_SESSION['bd_host'] . ';'; + $c = new PDO ($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options); + $sql = sprintf (SQL_CREATE_DB, $_SESSION['bd_base']); + $res = $c->query ($sql); + } catch (PDOException $e) { + } // on écrase la précédente connexion en sélectionnant la nouvelle BDD $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base']; @@ -590,7 +591,7 @@ function checkBD () { ); $ok = $stm->execute($values); } catch (PDOException $e) { - $error = true; + $ok = false; } if (!$ok) { -- cgit v1.2.3