You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wastesortingserver/api/QueryText.php

46 lines
1.9 KiB

<?php
5 years ago
require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/api/JsonResponse.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
//关键字查询
class QueryText
{
public static function get($sql, $keyword): AbstractGarbageQuery
{
$garbage_result = new class() extends AbstractGarbageQuery
{
5 years ago
// 参数绑定
5 years ago
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));
5 years ago
} else if (count($param) == 1) {
$stmt->bind_param(str_repeat("s", count($param)), $param[0]);
}
}
};
DbUtil::query($sql, $garbage_result, $keyword);
return $garbage_result;
}
}
if (empty($_GET)) {
json_res(json_encode(array("status" => false, "error" => "非法请求"), JSON_UNESCAPED_UNICODE));
} else if (isset($_GET["keyword"]) and !empty($_GET["keyword"])) {
5 years ago
$result = QueryGarbageWithName("select * from garbage where name like ?", array("%" . $_GET["keyword"] . "%"));
json_res(json_encode(array("status" => true, "result" => $result->getGarbageObjArray(), "keyword" => $_GET["keyword"]), JSON_UNESCAPED_UNICODE));
} else if (isset($_GET["category"]) and is_numeric($_GET["category"])) {
5 years ago
$result = QueryGarbageWithName("select * from garbage where category = ?", array((int)$_GET["category"]));
json_res(json_encode(array("status" => true, "result" => $result->getGarbageObjArray(), "category" => $_GET["category"]), JSON_UNESCAPED_UNICODE));
} else {
json_res(json_encode(array("status" => false, "error" => "非法查询参数"), JSON_UNESCAPED_UNICODE));
}