- $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'] . ';charset=utf8mb4';
- $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['mysql_server']."');", $content);
- $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['mysql_database']."');", $content);
+ if ($_POST['mysql_server'] != "") {$server = $_POST['mysql_server'];} // if server and database are filled
+ if ($_POST['mysql_database'] != "") {$database = $_POST['mysql_database'];}
+
+ $sql_structure = file_get_contents('install/mysql.sql');
+
+ if (isset($_POST['mysql_utf8_mb4'])) {
+ //with UTF8-MB4
+ $db_path = 'mysql:host=' . $server . ';dbname=' . $database . ';charset=utf8mb4';
+ $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password'], array(
+ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
+ ));
+ $content = str_replace("define ('MYSQL_USE_UTF8MB4', FALSE);", "define ('MYSQL_USE_UTF8MB4', TRUE);", $content);
+ } else { // regular UTF8
+ $sql_structure = str_replace(" DEFAULT CHARSET=utf8mb4", "", $sql_structure); // replace the UTF8-MB4 occurences inside the mysql.sql file
+ $db_path = 'mysql:host=' . $server . ';dbname=' . $database;
+ $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']);
+ }
+ $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+ $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$server."');", $content);
+ $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$database."');", $content);