method error documentation in bbn\Db\HasError
Set an error and acts appropriately based oon the error mode
function($e, bool $show_last = true, bool $show_backtrace = true)
{
$this->_has_error = true;
self::_set_has_error_all();
$msg = [
self::$LINE,
self::getLogLine('ERROR DB!'),
self::$LINE
];
if (\is_string($e)) {
$msg[] = self::getLogLine('USER MESSAGE');
$msg[] = $e;
}
elseif (method_exists($e, 'getMessage')) {
$msg[] = self::getLogLine('DB MESSAGE');
$msg[] = $e->getMessage();
}
$this->last_error = end($msg);
if ($show_last) {
$msg[] = self::getLogLine('QUERY');
$msg[] = $this->last();
if (($last_real_params = $this->getRealLastParams()) && !empty($last_real_params['values'])) {
$msg[] = self::getLogLine('VALUES');
foreach ($last_real_params['values'] as $v){
if ($v === null) {
$msg[] = 'NULL';
}
elseif (\is_bool($v)) {
$msg[] = $v ? 'TRUE' : 'FALSE';
}
elseif (\is_string($v)) {
$msg[] = Str::isBuid($v) ? bin2hex($v) : Str::cut($v, 30);
}
else{
$msg[] = $v;
}
}
}
}
if ($show_backtrace) {
$msg[] = self::getLogLine('BACKTRACE');
$last = '';
$i = 0;
$btr = array_map(function($a) use (&$last, &$i) {
$r = [
'dfile' => X::basename(
X::dirname($a['file'])).'/'.
X::basename($a['file']
),
'good' => false
];
if (($last === 'bbn/Db.php') && ($r['dfile'] !== $last)) {
$r['good'] = true;
}
$last = $r['dfile'];
$r['msg'] = "{$a['function']} (".
$r['dfile'] . ":{$a['line']})";
$i++;
return $r;
}, debug_backtrace());
$dbt = array_reverse($btr);
array_walk(
$dbt,
function ($a, $i) use (&$msg) {
if (isset($a['dfile'])) {
$msg[] = str_repeat($a['good'] ? '!' : ' ', $i).
($i ? '->' : '').$a['msg'];
}
}
);
}
$this->log(implode(PHP_EOL, $msg));
if ($this->on_error === Errors::E_EXCEPTION) {
throw new \Exception(X::join($msg, PHP_EOL));
}
elseif ($this->on_error === Errors::E_DIE) {
throw new \Exception(X::join($msg, PHP_EOL));
die();
}
}
Set an error and acts appropriately based oon the error mode BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2024
BBN Solutions