2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 define('MAX_DEADLOCK_RETRY', 3);
15 if (function_exists('mysqli_connect'))
16 include_once("connect_db_mysqli.inc");
18 include_once("connect_db_mysql.inc"); // use deprecated mysql_* API as fallback on old servers
20 function db_get_version()
22 $result = db_query("SELECT VERSION()");
23 $row = db_fetch($result);
28 Converts encoding name to mysql standard.
30 function get_mysql_encoding_name($encoding)
34 'ISO-8859-1' => 'latin1',
35 'ISO-8859-2' => 'latin2',
36 'ISO-8859-7' => 'greek',
37 'ISO-8859-8' => 'hebrew',
38 'ISO-8859-9' => 'latin5',
39 'ISO-8859-13' => 'latin7',
55 'SHIFT_JIS' => 'sjis',
56 'TIS-620' => 'tis620',
59 $encoding = strtoupper($encoding);
61 return isset($db_encoding[$encoding]) ? $db_encoding[$encoding] : null;
65 Returns 'best' mysql collation for various FA backend language codes.
67 function get_mysql_collation($lang=null)
70 $lang = 'utf8_'.substr($_SESSION['language']->code, 0, 2);
72 $db_collation = array(
73 'utf8_is' => 'utf8_icelandic_ci',
74 'utf8_lv' => 'utf8_latvian_ci',
75 'utf8_ro' => 'utf8_romanian_ci',
76 'utf8_sl' => 'utf8_slovenian_ci',
77 'utf8_pl' => 'utf8_polish_ci',
78 'utf8_et' => 'utf8_estonian_ci',
79 'utf8_es' => 'utf8_spanish_ci', // or 'spanish2',
80 'utf8_sw' => 'utf8_swedish_ci',
81 'utf8_tr' => 'utf8_turkish_ci',
82 'utf8_cs' => 'utf8_czech_ci',
83 'utf8_da' => 'utf8_danish_ci',
84 'utf8_lt' => 'utf8_lithuanian_ci',
85 'utf8_sk' => 'utf8_slovak_ci',
86 'utf8_sp' => 'utf8_spanish2_ci',
87 'utf8_fa' => 'utf8_persian_ci',
88 'utf8_hu' => 'utf8_hungarian_ci',
89 'utf8_fr' => 'utf8_roman_ci',
90 'utf8_it' => 'utf8_roman_ci',
93 return isset($db_collation[$lang]) ? $db_collation[$lang] : 'utf8_unicode_ci';
97 Later we assume that database with version less than 2.4 is old database,
98 which is subject to invalid encodings on text columns,
99 so no SET NAMES or equivalent should be used.
103 $result = db_query("SELECT value FROM ".TB_PREF."sys_prefs WHERE name='version_id'");
104 $data = db_fetch($result);
105 return !db_num_rows($result) // new database is fixed by default
106 || ($data[0] > "2.3rc");
110 Check database default charset.
112 function db_get_default_charset()
114 $result = db_query("SELECT @@character_set_database");
115 $var = db_fetch($result);
119 function db_get_view_schema($view)
123 $qry = "select view_definition from information_schema.views where table_schema=DATABASE() and table_name='$view'";
124 $res = db_query($qry,'Failed to select view schema');
125 if ($res && db_num_rows($res) == 1) {
126 $row = db_fetch_assoc($res);
127 $schema = $row['view_definition'];
133 SQL db profiling stub
135 if (!function_exists('db_profile'))
137 function db_profile($sql=false)