Forráskód Böngészése

Petits changements install

Alexandre Alapetite 12 éve
szülő
commit
e38b3a9c1b
2 módosított fájl, 10 hozzáadás és 9 törlés
  1. 1 1
      app/sql.php
  2. 9 8
      p/i/install.php

+ 1 - 1
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');

+ 9 - 8
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) {