Handle exceptions.
This commit is contained in:
parent
e6056ae34a
commit
50f04b3a3c
35
chat.php
35
chat.php
@ -15,25 +15,26 @@ 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) {
|
||||||
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 "<div class='private'>DB Error: ". $e->getMessage() . "<br> File: " . $e->getFile() . " (".$e->getLine().")</div>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_messages(){
|
function show_messages()
|
||||||
mysql_error_handler($chat = db::c()->query('
|
{
|
||||||
SELECT msg, msgdate, (SELECT login FROM users WHERE users.id = uid) AS from, type
|
try {
|
||||||
FROM `chat` ORDER BY `id` LIMIT 50'));
|
$chat = db::c()->query('
|
||||||
// try {
|
SELECT
|
||||||
// $chat = db::c()->query('
|
`msg`,
|
||||||
// SELECT
|
`msgdate`,
|
||||||
// `msg`,
|
(SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
|
||||||
// `msgdate`,
|
`type`
|
||||||
// (SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
|
FROM `chat` ORDER BY `id` LIMIT 50');
|
||||||
// `type`
|
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
||||||
// FROM `chat` ORDER BY `id` LIMIT 50');
|
echo "<div class='private'>DB Error: ". $e->getMessage() . "<br> File: " . $e->getFile() . " (".$e->getLine().")</div>";
|
||||||
// } 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']);
|
||||||
|
16
config.php
16
config.php
@ -31,22 +31,6 @@ 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…
x
Reference in New Issue
Block a user