From 3c0624b07bcfb97f3c8865232936d7b380e0a80a Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 7 Oct 2013 12:27:07 +0200 Subject: Fix issue #145: créé la BDD si elle n'existe pas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UTF-8 par défaut ;) Le comportement semble correct lorsqu'on n'a pas les droits de créer de tables --- public/install.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/public/install.php b/public/install.php index 65daed111..46605fe6b 100644 --- a/public/install.php +++ b/public/install.php @@ -8,6 +8,8 @@ if (isset ($_GET['step'])) { define ('STEP', 1); } +define ('SQL_REQ_CREATE_DB', 'CREATE DATABASE %s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;'); + define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` ( `id` varchar(6) NOT NULL, `name` varchar(255) NOT NULL, @@ -311,10 +313,26 @@ function checkBD () { $str = ''; $driver_options = null; if($_SESSION['bd_type'] == 'mysql') { - $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name']; $driver_options = array( 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_pass'], + $driver_options); + + $sql = sprintf (SQL_REQ_CREATE_DB, $_SESSION['bd_name']); + $res = $c->query ($sql); + + if (!$res) { + throw new PDOException(); + } + + // on écrase la précédente connexion en sélectionnant la nouvelle BDD + $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name']; } elseif($_SESSION['bd_type'] == 'sqlite') { $str = 'sqlite:' . PUBLIC_PATH . '/data/' . $_SESSION['bd_name'] . '.sqlite'; @@ -639,7 +657,9 @@ case 5: <?php echo _t ('freshrss_installation'); ?> - + + + -- cgit v1.2.3