Handle exceptions.
This commit is contained in:
parent
b51828ba2f
commit
e6056ae34a
37
chat.php
37
chat.php
@ -15,28 +15,25 @@ include_once "config.php";
|
|||||||
$msg = filter_input(INPUT_POST,'msg');
|
$msg = filter_input(INPUT_POST,'msg');
|
||||||
$uid = $_SESSION['uid'];
|
$uid = $_SESSION['uid'];
|
||||||
if ($msg) {
|
if ($msg) {
|
||||||
try {
|
mysql_error_handler(db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg));
|
||||||
db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg);
|
|
||||||
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
|
||||||
echo "DB Error: ". $e->getMessage() . PHP_EOL;
|
|
||||||
echo "File: " . $e->getFile() . "[".$e->getLine()."]". PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_messages()
|
function show_messages(){
|
||||||
{
|
mysql_error_handler($chat = db::c()->query('
|
||||||
try {
|
SELECT msg, msgdate, (SELECT login FROM users WHERE users.id = uid) AS from, type
|
||||||
$chat = db::c()->query('
|
FROM `chat` ORDER BY `id` LIMIT 50'));
|
||||||
SELECT
|
// try {
|
||||||
`msg`,
|
// $chat = db::c()->query('
|
||||||
`msgdate`,
|
// SELECT
|
||||||
(SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
|
// `msg`,
|
||||||
`type`
|
// `msgdate`,
|
||||||
FROM `chat` ORDER BY `id` LIMIT 50');
|
// (SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
|
||||||
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
// `type`
|
||||||
echo "DB Error: ". $e->getMessage() . PHP_EOL;
|
// FROM `chat` ORDER BY `id` LIMIT 50');
|
||||||
echo "File: " . $e->getFile() . " (".$e->getLine().")". PHP_EOL;
|
// } catch (\Krugozor\Database\Mysql\Exception $e) {
|
||||||
}
|
// echo "DB Error: ". $e->getMessage() . PHP_EOL;
|
||||||
|
// echo "File: " . $e->getFile() . " (".$e->getLine().")". PHP_EOL;
|
||||||
|
// }
|
||||||
|
|
||||||
while ($message = $chat->fetch_assoc()) {
|
while ($message = $chat->fetch_assoc()) {
|
||||||
$d = new DateTime($message['msgdate']);
|
$d = new DateTime($message['msgdate']);
|
||||||
|
18
config.php
18
config.php
@ -10,7 +10,7 @@ error_reporting(E_ALL);
|
|||||||
define("GAMEDOMAIN","combats.loc");
|
define("GAMEDOMAIN","combats.loc");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Запрещвем кэшировать
|
* Запрещаем кэшировать
|
||||||
*/
|
*/
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||||
@ -31,6 +31,22 @@ spl_autoload_register(function ($class_name) {
|
|||||||
include_once 'classes/' . $class_name . '.php';
|
include_once 'classes/' . $class_name . '.php';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Выбрасыватель ошибок для запросов в базу
|
||||||
|
*/
|
||||||
|
function mysql_error_handler($query) {
|
||||||
|
try {
|
||||||
|
$query;
|
||||||
|
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
||||||
|
echo <<<MYSQL_ERROR
|
||||||
|
<div style="background-color: #eecccc; border: 1px solid #eeaaaa; padding: 1em; font-size: 0.5em;">
|
||||||
|
<strong style="color: #8F0000">DB Error:</strong> {$e->getMessage()}<br>
|
||||||
|
<strong>File:</strong> {$e->getFile()} ({$e->getLine()})
|
||||||
|
</div>
|
||||||
|
MYSQL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* === Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонаж на которого нельзя напасть. === */
|
/* === Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонаж на которого нельзя напасть. === */
|
||||||
$unkilable = [
|
$unkilable = [
|
||||||
'rooms' => [620, 621, 1051, 1052],
|
'rooms' => [620, 621, 1051, 1052],
|
||||||
|
Loading…
Reference in New Issue
Block a user