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.8 KiB

<?php
require_once "../config.php";
require_once __ROOT__ . "/api/JsonResponse.php";
require_once __ROOT__ . "/database/DbUtil.php";
require_once __ROOT__ . "/database/Query.php";
//关键字查询
class QueryText
{
public static function get($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 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"])) {
$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"])) {
$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));
}