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' collation for various locale language codes
67 function get_mysql_collation($lang=null)
70 $lang = substr($_SESSION['language']->code, 0, 2);
72 $db_collation = array(
79 'es' => 'spanish', // or 'spanish2',
93 return 'utf8_'.(isset($db_collation[$lang]) ? $db_collation[$lang] : '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);
120 SQL db profiling stub
122 if (!function_exists('db_profile'))
124 function db_profile($sql=false)