diff --git a/chat.php b/chat.php index e401caa..fe2f07f 100644 --- a/chat.php +++ b/chat.php @@ -15,25 +15,26 @@ include_once "config.php"; $msg = filter_input(INPUT_POST,'msg'); $uid = $_SESSION['uid']; if ($msg) { - mysql_error_handler(db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $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() . "
File: " . $e->getFile() . " (".$e->getLine().")
"; + } } -function show_messages(){ - mysql_error_handler($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')); -// 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() . PHP_EOL; -// echo "File: " . $e->getFile() . " (".$e->getLine().")". PHP_EOL; -// } +function show_messages() +{ + 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() . "
File: " . $e->getFile() . " (".$e->getLine().")
"; + } while ($message = $chat->fetch_assoc()) { $d = new DateTime($message['msgdate']); diff --git a/config.php b/config.php index f4bc06f..af374e4 100644 --- a/config.php +++ b/config.php @@ -31,22 +31,6 @@ spl_autoload_register(function ($class_name) { include_once 'classes/' . $class_name . '.php'; }); -/** - * Выбрасыватель ошибок для запросов в базу - */ -function mysql_error_handler($query) { - try { - $query; - } catch (\Krugozor\Database\Mysql\Exception $e) { - echo << - DB Error: {$e->getMessage()}
- File: {$e->getFile()} ({$e->getLine()}) - -MYSQL_ERROR; - } -} - /* === Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонаж на которого нельзя напасть. === */ $unkilable = [ 'rooms' => [620, 621, 1051, 1052],