bind_result($col1, $col2, $col3, $col4, $col5, $col6, $col7, $col8); while ($stmt->fetch()) { array_push($this->token_array, new ApiToken($col1, $col2, $col3, $col4, $col5, $col6, $col7, $col8)); } } /** * @return array */ public function getTokenArray(): array { return $this->token_array; } function getToken(): ApiToken { return $this->token_array[0]; } } //垃圾分类查询 abstract class AbstractGarbageQuery implements DoExcute { // 垃圾分类查询结果 private $garbage_obj_array = array(); public function doResult(mysqli_stmt $stmt) { $stmt->bind_result($col1, $col2, $col3, $col4); while ($stmt->fetch()) { $g = new Garbage($col1, $col2, $col3, $col4); array_push($this->garbage_obj_array, $g); } } /** * @return array */ public function getGarbageObjArray(): array { return $this->garbage_obj_array; } } function getGarbageQuery($sql, $keyword): AbstractGarbageQuery { $garbage_result = new class() extends AbstractGarbageQuery { public function bind_param(mysqli_stmt $stmt, array $param = null) { if (count($param) > 1) { $stmt->bind_param(str_repeat("s", count($param)), $param[0], ...array_slice($param, 1)); } else { $stmt->bind_param(str_repeat("s", count($param)), $param[0]); } } }; DbUtil::query($sql, $garbage_result, $keyword); return $garbage_result; } class QuestionQuery implements DoExcute { private $question_array = array(); public function bind_param(mysqli_stmt $stmt, array $param = null) { } public function doResult(mysqli_stmt $stmt) { $stmt->bind_result($col1, $col2); while ($stmt->fetch()) { $q = new Question($col1, $col2); array_push($this->question_array, $q); } } /** * @return array */ public function getQuestionArray(): array { return $this->question_array; } } //查询问题答案 class AnswerQuery implements DoExcute { private $answer_array = array(); public function bind_param(mysqli_stmt $stmt, array $param = null) { if (!empty($param)) { $stmt->bind_param("i", $param[0]); } } public function doResult(mysqli_stmt $stmt) { $stmt->bind_result($col1, $col2, $col3, $col4); while ($stmt->fetch()) { $a = new Answer($col1, $col2, $col3, $col4); array_push($this->answer_array, $a); } } /** * @return array */ public function getAnswerArray(): array { return $this->answer_array; } } //查询问题 class QueryRandQuestion implements DoExcute { public function bind_param(mysqli_stmt $stmt, array $param = null) { } public function doResult(mysqli_stmt $stmt) { $stmt->bind_result($col1, $col2, $col3, $col4, $col5); while ($stmt->fetch()) { } } } ;