-function set_global_connection($company=-1)
-{
- global $db, $transaction_level;
-
- cancel_transaction(); // cancel all aborted transactions if any
- $transaction_level = 0;
-
- $db = $_SESSION["wa_current_user"]->get_db_connection($company);
-
- return $db;
-}
-
-$db_duplicate_error_code = 1062;
-
-//DB wrapper functions to change only once for whole application
-
-function db_query($sql, $err_msg=null)
-{
- global $db, $show_sql, $sql_trail, $select_trail, $go_debug, $sql_queries, $Ajax,
- $db_connections;
-
- // set current db prefix
- $cur_prefix = $db_connections[$_SESSION["wa_current_user"]->cur_con]['tbpref'];
- $sql = str_replace(TB_PREF, $cur_prefix, $sql);
-
- if ($show_sql)
- {
- $Ajax->activate('footer_debug');
- $sql_queries .= "<pre>$sql</pre>\n<hr>";
- }
-
- $result = mysql_query($sql, $db);
- if($sql_trail) {
- if ($select_trail || (strstr($sql, 'SELECT') === false)) {
- mysql_query(
- "INSERT INTO ".$cur_prefix."sql_trail
- (`sql`, `result`, `msg`)
- VALUES(".db_escape($sql).",".($result ? 1 : 0).",
- ".db_escape($err_msg).")", $db);
- }
- }
-
- if ($err_msg != null || $go_debug) {
- $exit = $err_msg != null;
- if (function_exists('xdebug_call_file'))
- check_db_error('<br>At file '.xdebug_call_file().':'.xdebug_call_line().':<br>'.$err_msg, $sql, $exit);
- else
- check_db_error($err_msg, $sql, $exit);
- }
- return $result;
-}