From c92d45debd2639829b221ac2496534a369134847 Mon Sep 17 00:00:00 2001 From: hecht Date: Mon, 24 Oct 2016 20:25:10 +0000 Subject: [PATCH] added a silent query and added the use of it in some places (where db_query may fail) --- ag/include/clan_chat.inc.php | 2 +- ag/include/clan_fights.inc.php | 2 +- ag/include/defines.inc.php | 4 ++-- ag/include/event.inc.php | 12 ------------ ag/include/kampf_wrapper.inc.php | 2 +- ag/include/sqlwrapper.inc.php | 8 ++++++++ ag/include/tasking.inc.php | 6 ------ ag/include/user.inc.php | 2 +- 8 files changed, 14 insertions(+), 24 deletions(-) diff --git a/ag/include/clan_chat.inc.php b/ag/include/clan_chat.inc.php index c4e7597..4a713fd 100644 --- a/ag/include/clan_chat.inc.php +++ b/ag/include/clan_chat.inc.php @@ -44,7 +44,7 @@ function checkAccessRights($user_id, $clan_chat_id) { if($user_id == NULL) { return false; } - $qry = db_query('SELECT clan_chat_id FROM clan_chatroom_clans cc INNER JOIN user u ON cc.clan_id = u.clan WHERE cc.clan_chat_id = ' . $clan_chat_id . ' and u.id = ' .$user_id); + $qry = silent_query('SELECT clan_chat_id FROM clan_chatroom_clans cc INNER JOIN user u ON cc.clan_id = u.clan WHERE cc.clan_chat_id = ' . $clan_chat_id . ' and u.id = ' .$user_id); if(!$qry) { return false; } diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index a08c7af..3a446cf 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -468,7 +468,7 @@ function getParticipatingClanIDs($clan_challenge_id) { function getParticipatingClanData($clan_challenge_id, $clan_id) { $sql = 'SELECT * FROM clan_challenge_clans AS ccp WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = ' .$clan_id; - $qry = db_query($sql); + $qry = silent_query($sql); if(!$qry) { echo $sql .'
'; } diff --git a/ag/include/defines.inc.php b/ag/include/defines.inc.php index 9a0e44c..986b7d4 100644 --- a/ag/include/defines.inc.php +++ b/ag/include/defines.inc.php @@ -59,7 +59,7 @@ function getDefines($prefix = NULL) { } $sql = 'SELECT * FROM defines WHERE editable = 1 AND ' . $appendix; - $qry = db_query(); + $qry = silent_query(); if(!$qry) { return 'Fehler in SQL-Anweisung'; @@ -79,7 +79,7 @@ function setDefine($key, $value) { } // set where editable true $sql = 'UPDATE defines SET `value` = \''.$value.'\' WHERE `key` = \''.$key.'\' AND editable = TRUE'; - $qry = db_query($sql); + $qry = silent_query($sql); if(!$qry || db_affected_rows() == 0) { return 'Konnte den define ' . $key . ' nicht auf ' . $value . ' setzen'; } diff --git a/ag/include/event.inc.php b/ag/include/event.inc.php index cfb32b7..2e851be 100644 --- a/ag/include/event.inc.php +++ b/ag/include/event.inc.php @@ -187,8 +187,6 @@ function isEventToFetchAwaiting($charid) { function getEventIdsToFetch($char_id) { $sql = 'SELECT event_id FROM event_chars e WHERE block_end < now() and abgeholt = FALSE AND char_id = ' .$char_id . ' ORDER BY event_id ASC'; $qry = db_query($sql); - if(!$qry) - echo $sql . '
'; $result = array(); while ($row = mysqli_fetch_row($qry)) { @@ -256,8 +254,6 @@ function abholenChar(array $user, $event_id, $char_id) { // Okay and now we want to learn the attacks :) $sql = 'SELECT attack, count(attack) as anzahl FROM event_fight_rounds e where event_id = ' . $event_id . ' AND event_char_id = ' . $char_id . ' group by attack'; $qry = db_query($sql); - if(!$qry) - echo $sql .'
'; $attacken_usage = array(); while($row = mysqli_fetch_assoc($qry)) { @@ -268,8 +264,6 @@ function abholenChar(array $user, $event_id, $char_id) { $sql = 'UPDATE event_chars SET abgeholt = TRUE WHERE char_id = ' . $char_id . ' AND event_id = ' . $event_id; $qry = db_query($sql); - if(!$qry) - echo $sql .'
'; semaphoreDown($ressource); // free the previously reserved semaphore! return $fight_ids; // Return the fight ids that the char has participated in! @@ -319,8 +313,6 @@ function getEventFightIds($event_id) { function getEventFightIdsByChar($event_id, $event_char_id) { $sql = 'SELECT event_fight_id FROM event_fight_rounds where event_id = ' . $event_id . ' AND event_char_id = ' . $event_char_id . ' AND `round` = 0 ORDER BY event_fight_id ASC'; $qry = db_query($sql); - if(!$qry) - echo $sql . '
'; while($row = mysqli_fetch_assoc($qry)) { $result[]= $row['event_fight_id']; } @@ -331,10 +323,6 @@ function getEventFightRoundData($event_id, $event_fight_id, $round) { $sql = 'SELECT * FROM event_fight_rounds WHERE event_id = ' . $event_id . ' AND event_fight_id = ' . $event_fight_id . ' AND `round` = ' .$round; $qry = db_query($sql); - if(!$qry) { - echo $sql . '
'; - return; - } while($row = mysqli_fetch_assoc($qry)) { $result[$row['event_char_id']] = $row; } diff --git a/ag/include/kampf_wrapper.inc.php b/ag/include/kampf_wrapper.inc.php index 584cdf0..8e1efc9 100644 --- a/ag/include/kampf_wrapper.inc.php +++ b/ag/include/kampf_wrapper.inc.php @@ -20,7 +20,7 @@ function convertLearnIDToAttackID (array $learnids, $char_id) { $sql = 'SELECT id, at_id FROM lernen WHERE id IN ('.implode(',', $learnids).') AND besitzer = ' . $char_id; // echo $sql .'
'; - $qry = db_query($sql); + $qry = silent_query($sql); if (!$qry) { return array(); } diff --git a/ag/include/sqlwrapper.inc.php b/ag/include/sqlwrapper.inc.php index 1dc3bc5..9a72971 100755 --- a/ag/include/sqlwrapper.inc.php +++ b/ag/include/sqlwrapper.inc.php @@ -6,10 +6,18 @@ * @author hecht */ +function silent_query($sql) { + return mysqli_query($GLOBALS['main_db'], $sql); +} + function db_query($sql) { $qry = mysqli_query($GLOBALS['main_db'], $sql); if(!$qry) { echo $sql . '
'; + die('Query failed: ' + .'
  • errorno='.mysqli_errno($GLOBALS['main_db']) + .'
  • error='.mysqli_error($GLOBALS['main_db']) + .'
  • query='.$query); } return $qry; } diff --git a/ag/include/tasking.inc.php b/ag/include/tasking.inc.php index 376c4fe..809d532 100644 --- a/ag/include/tasking.inc.php +++ b/ag/include/tasking.inc.php @@ -76,8 +76,6 @@ function schedule($script_name, array $parameters, $execution_time, $repeat_mode */ function getAllTaskIds() { $qry = db_query('SELECT task_id FROM tasking'); - if(!$qry) - return array(); $result = array(); while($row = mysqli_fetch_row($qry)) { $result[] = $row[0]; @@ -93,8 +91,6 @@ function getPassedTaskIds($timestamp = NULL) { $timestamp = time(); } $qry = db_query('SELECT task_id FROM tasking WHERE schedule_time <= ' . $timestamp); - if(!$qry) - return array(); $result = array(); while($row = mysqli_fetch_row($qry)) { $result[] = $row[0]; @@ -108,8 +104,6 @@ function getPassedTaskIds($timestamp = NULL) { */ function getTask($task_id) { $qry = db_query('SELECT * FROM tasking WHERE task_id = ' . $task_id); - if(!$qry) - return null; return mysqli_fetch_assoc($qry); } diff --git a/ag/include/user.inc.php b/ag/include/user.inc.php index 93b1719..69c3155 100644 --- a/ag/include/user.inc.php +++ b/ag/include/user.inc.php @@ -130,7 +130,7 @@ function encryptPassword($password){ function getUserMetaData($userid) { $sql = 'SELECT * FROM user_meta_data WHERE user_id = ' . $userid; - $qry = db_query($sql); + $qry = silent_query($sql); $result = array(); if(!$qry)