blob: 293707a22db0ea3b3ab16016c32643c889be6e43 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class db {
3 const EXPORT_DB_FORMAT_SQL = 0;
4
5 public static function sanitize($string) {
6 global $con;
7 return mysqli_real_escape_string($con, $string);
8 }
9
10 public static function needsSetUp() {
11 global $con;
12
13 $checkquery = mysqli_query($con, "SELECT 1 FROM people LIMIT 1");
14
15 return ($checkquery === false);
16 }
17
18 public static function numRows($table) {
19 global $con;
20
21 $stable = preg_replace("/[^A-Za-z0-9 ]/", '', $table);
22
23 $query = mysqli_query($con, "SELECT 1 FROM $stable");
24
25 if ($query === false) return -1;
26
27 return mysqli_num_rows($query);
28 }
29
30 public static function limitPagination($start, $limit) {
31 $slimit = (int)$limit;
32 $sstart = $slimit*(int)$start;
33 if ($slimit > 100 || $slimit < 0) return false;
34 if ($sstart < 0) return false;
35
36 return ($slimit == 0 ? "" : " LIMIT $sstart,$slimit");
37 }
38}