";foreach ($result as $item) {echo "
$item
";}echo "";} else {echo "没有找到符合条件的服务";}
}
function search_service($service, $location) {// 连接数据库$conn = connect_db();// 编写SQL语句$sql = "SELECT FROM services WHERE service=? AND location=?";// 预处理SQL语句$stmt = $conn->prepare($sql);// 绑定参数$stmt->bind_param('ss', $service, $location);// 执行SQL语句$stmt->execute();// 获取结果$result = $stmt->get_result();// 关闭连接$stmt->close();$conn->close();// 返回结果return $result->fetch_all();
}
function connect_db() {$host = 'localhost';$user = 'root';$password = '';$db = 'services';// 创建连接$conn = new mysqli($host, $user, $password, $db);// 检测连接if ($conn->connect_error) {die("连接失败:" . $conn->connect_error);}// 设置编码$conn->set_charset('utf8');// 返回连接return $conn;
}
?>