Merge branch 'fronkdev' into 'master'

Added more debugging to SQL errors/warnings

See merge request fronk/thetool!858
This commit is contained in:
Frank Schubert
2025-01-07 18:55:33 +00:00
2 changed files with 281 additions and 260 deletions
+4 -4
View File
@@ -398,10 +398,10 @@ class ContractController extends mfBaseController {
$contract_data['matchcode'] = trim($r->matchcode);
$contract_data['termination_id'] = $r->termination_id;
$contract_data['amount'] = 1;
$contract_data['price'] = $r->price;
$contract_data['price_setup'] = $r->price_setup;
$contract_data['price_nne'] = $r->price_nne;
$contract_data['price_nbe'] = $r->price_nbe;
$contract_data['price'] = Layout::commaToDot(trim($r->price));
$contract_data['price_setup'] = Layout::commaToDot(trim($r->price_setup));
$contract_data['price_nne'] = Layout::commaToDot(trim($r->price_nne));
$contract_data['price_nbe'] = Layout::commaToDot(trim($r->price_nbe));
$contract_data['note'] = trim($r->note);
/*
+32 -11
View File
@@ -1,4 +1,5 @@
<?php
class FronkDB {
public $link;
@@ -7,6 +8,7 @@ class FronkDB {
private $log;
private static $instances = [];
//private static $instance;
public function __construct($host = false, $user = false, $pass = false, $db = false) {
@@ -86,18 +88,39 @@ class FronkDB {
}
try {
if($this->result=mysqli_query($this->link,$sql)) {
return $this->result;
} else {
$this->result = mysqli_query($this->link, $sql);
$return = $this->result;
$log_query = false;
// check for errors
if(!$this->result) {
$return = false;
$this->lastError = mysqli_error($this->link);
if($print_error) {
echo "Error in SQL-query:<br />\n" . $sql . "<br />\n" . $this->lastError . "<br />\n";
}
$this->log->warn("SQL Query failed: $sql");
return false;
$this->log->warn("SQL Last Error: ".$this->lastError);
}
} catch (\Exception $e) {
$this->log->warn("SQL Query Exception ".$e->getCode().": ". $e->getMessage()."\nQuery was:\n$sql");
// check for warnings
if(mysqli_warning_count($this->link) > 0) {
$log_query = true;
$warning = mysqli_get_warnings($this->link);
if($warning !== false) {
do {
$this->log->warn("SQL Warning: ".$warning->errno." - ".$warning->message);
} while ($warning->next());
}
}
if($log_query) {
$this->log->warn("SQL Query was: $sql");
}
return $return;
} catch(Exception $e) {
$this->log->warn("SQL Query Exception " . $e->getCode() . ": " . $e->getMessage() . "\nQuery was:\n$sql\n".$e->getTraceAsString());
throw $e;
}
}
@@ -219,8 +242,7 @@ class FronkDB {
// Build field/value pairs string
foreach($_data as $f => $v)
{
foreach($_data as $f => $v) {
$_Q = "'";
if(is_string($v)) {
$v = $this->escape($v);
@@ -273,8 +295,7 @@ class FronkDB {
$fstr = "";
foreach($fields as $f)
{
foreach($fields as $f) {
$fstr .= ",`$f`";
if($f == "*") $fstr = "*";
}