X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdb%2Fconnect_db_mysqli.inc;h=7359a85c6f731bd0629764361ea3eca42ff87fca;hb=40c3b111b007ad16a2eedff175e1612150191d04;hp=c5c1d69b761ff3814ee1eeb6a032503bc8c597b8;hpb=3df0648d1513215ea28378e679d4291d3e609ba6;p=fa-stable.git diff --git a/includes/db/connect_db_mysqli.inc b/includes/db/connect_db_mysqli.inc index c5c1d69b..7359a85c 100644 --- a/includes/db/connect_db_mysqli.inc +++ b/includes/db/connect_db_mysqli.inc @@ -9,17 +9,20 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +define('DB_DUPLICATE_ERROR', 1062); +define('SQL_MODE', ''); // STRICT_ALL_TABLES,NO_ZERO_IN_DATE ? + +$db_last_inserted_id = 0; function set_global_connection($company=-1) { - global $db, $transaction_level, $path_to_root, $db_connections; + global $db, $path_to_root, $db_connections; include ($path_to_root . "/config_db.php"); if ($company == -1) - $company = $_SESSION["wa_current_user"]->company; + $company = user_company(); - cancel_transaction(); // cancel all aborted transactions if any - $transaction_level = 0; + cancel_transaction(); // cancel all aborted transactions (if any) $_SESSION["wa_current_user"]->cur_con = $company; @@ -32,46 +35,37 @@ function set_global_connection($company=-1) ///// This non empty sql_mode values can interphere with FA, so all is set empty during ///// our sessions. ///// We are, however, investigating the existing code to be compatible in the future. - if (strncmp(db_get_version(), "5.6", 3) >= 0) - db_query("SET sql_mode = ''"); + db_query("SET sql_mode = '".SQL_MODE."'"); ///// 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, $db_last_inserted_id; - + global $db, $SysPrefs, $sql_queries, $Ajax, $db_connections, $db_last_inserted_id; + // set current db prefix $comp = isset($_SESSION["wa_current_user"]->cur_con) ? $_SESSION["wa_current_user"]->cur_con : 0; $cur_prefix = $db_connections[$comp]['tbpref']; $sql = str_replace(TB_PREF, $cur_prefix, $sql); - if ($show_sql) + if ($SysPrefs->show_sql) { $Ajax->activate('footer_debug'); $sql_queries .= "
$sql
\n
"; } - // mysql profiling - global $profile_sql; - if (@$profile_sql) - get_usec(); + db_profile(); // mysql profiling + $result = mysqli_query($db, $sql); - if (@$profile_sql) - { - $profile_sql= false; - _vd($sql.'
:'.db_num_rows($result).'rows, '.get_usec()); - } - - if($sql_trail) { + + db_profile($sql); + + if($SysPrefs->sql_trail) { $db_last_inserted_id = mysqli_insert_id($db); // preserve in case trail insert is done - if ($select_trail || (strstr($sql, 'SELECT') === false)) { + if ($SysPrefs->select_trail || (strstr($sql, 'SELECT') === false)) { mysqli_query($db, "INSERT INTO ".$cur_prefix."sql_trail (`sql`, `result`, `msg`) VALUES(".db_escape($sql).",".($result ? 1 : 0).", @@ -79,7 +73,7 @@ function db_query($sql, $err_msg=null) } } - if ($err_msg != null || $go_debug) { + if ($err_msg != null || $SysPrefs->go_debug) { $exit = $err_msg != null; if (function_exists('xdebug_call_file')) check_db_error('
At file '.xdebug_call_file().':'.xdebug_call_line().':
'.$err_msg, $sql, $exit); @@ -133,7 +127,7 @@ function db_escape($value = "", $nullify = false) global $db; $value = @html_entity_decode($value, ENT_QUOTES, $_SESSION['language']->encoding); - $value = @htmlspecialchars($value, ENT_QUOTES, $_SESSION['language']->encoding); + $value = html_specials_encode($value); //reset default if second parameter is skipped $nullify = ($nullify === null) ? (false) : ($nullify); @@ -168,9 +162,9 @@ function db_error_msg($conn) function db_insert_id() { - global $db_last_inserted_id, $sql_trail, $db; + global $db_last_inserted_id, $SysPrefs, $db; - return $sql_trail ? $db_last_inserted_id : mysqli_insert_id($db); + return $SysPrefs->sql_trail ? $db_last_inserted_id : mysqli_insert_id($db); } function db_num_affected_rows() @@ -188,11 +182,10 @@ function db_field_name($result, $n) function db_create_db($connection) { $db = mysqli_connect($connection["host"], $connection["dbuser"], $connection["dbpassword"]); - if (strncmp(db_get_version(), "5.6", 3) >= 0) - db_query("SET sql_mode = ''"); + if (!mysqli_select_db($db, $connection["dbname"])) { - $sql = "CREATE DATABASE IF NOT EXISTS " . $connection["dbname"] . ""; + $sql = "CREATE DATABASE IF NOT EXISTS `" . $connection["dbname"] . "`"; if (!mysqli_query($db, $sql) || !mysqli_select_db($db, $connection["dbname"])) return 0; }