Transaction references extended with parametrized patterns, added check_reference...
[fa-stable.git] / includes / db / connect_db_mysql.inc
index 622745ce7ab166a8056928d7fd0c55aacc205e19..aa30740fb869ae5c19228c94398f04e8d889b63a 100644 (file)
@@ -14,7 +14,7 @@ define('SQL_MODE', ''); // STRICT_ALL_TABLES,NO_ZERO_IN_DATE ?
 
 function set_global_connection($company=-1)
 {
-       global $db, $path_to_root, $db_connections;
+       global $db, $path_to_root, $db_connections, $SysPrefs;
 
        include ($path_to_root . "/config_db.php");
        if ($company == -1) 
@@ -35,6 +35,7 @@ function set_global_connection($company=-1)
        ///// We are, however, investigating the existing code to be compatible in the future.
                db_query("SET sql_mode = '".SQL_MODE."'");
        /////
+       $SysPrefs->refresh();
        return $db;
 }
 
@@ -185,6 +186,15 @@ function db_field_name($result, $n)
        return mysql_field_name($result, $n);
 }
 
+function db_set_collation($db, $fa_collation)
+{
+       return mysql_query("ALTER DATABASE COLLATE ".get_mysql_collation($fa_collation), $db);
+}
+
+/*
+       Create database for FA company. If database already exists,
+       just set collation to be sure nothing weird will happen later.
+*/
 function db_create_db($connection)
 {
        $db = mysql_connect($connection["host"] ,
@@ -192,10 +202,15 @@ function db_create_db($connection)
 
        if (!mysql_select_db($connection["dbname"], $db))
        {
-               $sql = "CREATE DATABASE IF NOT EXISTS " . $connection["dbname"] . "";
+               $sql = "CREATE DATABASE IF NOT EXISTS `" . $connection["dbname"] . "`"
+                       . " DEFAULT COLLATE '" . get_mysql_collation($connection["collation"]) . "'";
+
                if (!mysql_query($sql) || !mysql_select_db($connection["dbname"], $db))
+                               return 0;
+       } else
+               if (!db_set_collation($connection["collation"], $db))
                        return 0;
-       }
+
        return $db;
 }