dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname); if ($DB->connect_error) { die("Connection failed: " . $DB->connect_error); } $DB->set_charset("utf8"); } function switchQuestionnaireActive ($hash) { global $DB; connect(); $sql = "UPDATE questionnaire SET active = not active WHERE view_hash = ?"; if (!($stmt = $DB->prepare($sql))) { die("Prepare failed: (" . $DB->errno . ") " . $DB->error); } $stmt->bind_param('s', $hash); $stmt->execute(); $stmt->close(); $DB->close(); return; } function getQuestionnairesTotal () { global $DB; connect(); $sql = "SELECT count(id) FROM questionnaire"; if (!($stmt = $DB->prepare($sql))) { die("Prepare failed: (" . $DB->errno . ") " . $DB->error); } $stmt->execute(); $stmt->bind_result($count); $stmt->fetch(); $stmt->free_result(); $stmt->close(); $DB->close(); return $count; } function paginateQuestionnaire ($page, $no_of_records_per_page) { global $DB; connect(); $sql = "SELECT title, email, view_hash, active FROM questionnaire LIMIT ?, ?"; if (!($stmt = $DB->prepare($sql))) { die("Prepare failed: (" . $DB->errno . ") " . $DB->error); } if (!$stmt->bind_param("ii", $page,$no_of_records_per_page)) { die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error); } if (!$stmt->execute()) { die("Execute failed: (" . $stmt->errno . ") " . $stmt->error); } $stmt->store_result(); $stmt->bind_result($title, $email, $hash, $active); $all_data = array(); while ($stmt->fetch()) { $all_data[] = ['title' => $title, 'email' => $email, 'view_hash' => $hash, 'active' => $active]; } $stmt->free_result(); $stmt->close(); $DB->close(); return $all_data; }