partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 60e1fa616bf12d413cf6e3c64b4d793676446d33
parent 6109c7b38f3d67432dd03dd29541fa8e0a367a2f
Author: Felicitus <felicitus@felicitus.org>
Date:   Tue, 20 Dec 2011 09:36:06 +0100

Added a test to make sure that the DB encoding is UTF-8

Diffstat:
Msrc/setup/tests/check-database-connectivity.php | 23++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/setup/tests/check-database-connectivity.php b/src/setup/tests/check-database-connectivity.php @@ -25,7 +25,8 @@ switch ($_REQUEST["driver"]) { 'dbname' => $_REQUEST["dbname"], 'user' => $_REQUEST["user"], 'password' => $_REQUEST["password"], - 'host' => $_REQUEST["host"], + 'host' => $_REQUEST["host"], + 'charset' => 'utf8' ); if (isset($_REQUEST['port'])) { @@ -52,6 +53,26 @@ try { exit; } +/* Run additional tests */ +switch ($_REQUEST["driver"]) { + case "mysql": + performAdditionalMySQLTests($conn, $_REQUEST["dbname"]); + break; +} + +function performAdditionalMySQLTests ($connection, $dbname) { + $statement = $connection->prepare("SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = :schema"); + $statement->bindValue("schema", $dbname); + $statement->execute(); + + $encoding = $statement->fetchColumn(0); + + if ($encoding != "utf8") { + echo json_encode(array("error" => true, "errormessage" => "Your database doesn't have the proper encoding. Please change it using the following SQL statement: <br/><br/><code>ALTER DATABASE ".$dbname." CHARACTER SET utf8;</code>")); + exit; + } + +} echo json_encode(array("error" => false)); /**