Handle exceptions.
This commit is contained in:
parent
1b6cf440c2
commit
0892729efb
32
chat.php
32
chat.php
@ -14,26 +14,36 @@ include_once "config.php";
|
||||
|
||||
$msg = filter_input(INPUT_POST,'msg');
|
||||
$uid = $_SESSION['uid'];
|
||||
if ($msg) db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg);
|
||||
if ($msg) {
|
||||
try {
|
||||
db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg);
|
||||
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
||||
echo "DB Error:". $e->getMessage() ."On Line:". $e->getLine();
|
||||
}
|
||||
}
|
||||
|
||||
function show_messages()
|
||||
{
|
||||
$chat = db::c()->query('
|
||||
SELECT
|
||||
`msg`,
|
||||
`msgdate`,
|
||||
(SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
|
||||
`type`
|
||||
FROM `chat` ORDER BY `id` ASC LIMIT 50');
|
||||
try {
|
||||
$chat = db::c()->query('
|
||||
SELECT
|
||||
`msg`,
|
||||
`msgdate`,
|
||||
(SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
|
||||
`type`
|
||||
FROM `chat` ORDER BY `id` LIMIT 50');
|
||||
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
||||
echo "DB Error:". $e->getMessage() ."On Line:". $e->getLine();
|
||||
}
|
||||
|
||||
while ($message = $chat->fetch_assoc()) {
|
||||
$d = new DateTime($message['msgdate']);
|
||||
$m = htmlspecialchars($message['msg']);
|
||||
if ($message['type'] == 'sys') { /* Системка */
|
||||
echo sprintf('<span style="color:maroon;background:#faa;">%s %s</span>', $d->format('H:i'),$m)." <br>";
|
||||
echo sprintf('<span style="color:maroon;background:#faa;">%s %s</span>', $d->format('H:i'),$m).PHP_EOL;
|
||||
} elseif ($message['type'] == 'sms') { /* Телеграмма */
|
||||
echo sprintf('<span style="color:darkgreen;background:#afa;">[Телеграмма]: %s %s</span>', $d->format('H:i'),$m)." <br>";
|
||||
} else echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m)." <br>";
|
||||
echo sprintf('<span style="color:darkgreen;background:#afa;">[Телеграмма]: %s %s</span>', $d->format('H:i'),$m).PHP_EOL;
|
||||
} else {echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m).PHP_EOL;}
|
||||
}
|
||||
}
|
||||
show_messages();
|
||||
|
Loading…
Reference in New Issue
Block a user