在PHP中使用存储在数据库中的MySQL查询

时间:2019-05-15 18:43:27

标签: php mysql

我有一个MySQL查询数据库,需要在PHP中输出。查询中包含<和>,并且这些都将转换为html标签,因此不会输出整个查询。如何在不更改<>的情况下输出它?

SELECT
  (CASE WHEN measure_start IS NULL AND fy_month = 1 AND fy_day = 1
    THEN YEAR(measure_date)
   WHEN measure_start IS NULL AND MONTH(measure_date) > fy_month
     THEN CONCAT(YEAR(measure_date), '' - '', YEAR(measure_date) + 1)
   WHEN measure_start IS NULL AND MONTH(measure_date) > fy_month
     THEN CONCAT(YEAR(measure_date) - 1, '' - '', YEAR(measure_date))
   WHEN measure_start IS NULL AND MONTH(measure_date) = fy_month AND DAY(measure_date) >= fy_day
     THEN CONCAT(YEAR(measure_date), '' - '', YEAR(measure_date) + 1)
   WHEN measure_start IS NULL AND MONTH(measure_date) = fy_month AND DAY(measure_date) < fy_day
     THEN CONCAT(YEAR(measure_date) - 1, '' - '', YEAR(measure_date))
   WHEN measure_date IS NULL AND fy_month = 1 AND fy_day = 1
     THEN YEAR(measure_start)
   WHEN measure_date IS NULL AND MONTH(measure_start) > fy_month
     THEN CONCAT(YEAR(measure_start), '' - '', YEAR(measure_start) + 1)
   WHEN measure_date IS NULL AND MONTH(measure_start) < fy_month
     THEN CONCAT(YEAR(measure_start) - 1, '' - '', YEAR(measure_start))
   WHEN measure_date IS NULL AND MONTH(measure_start) = fy_month AND DAY(measure_start)d>=fy_day
     THEN CONCAT(YEAR(measure_start), '' - '', YEAR(measure_start) + 1)
   WHEN measure_date IS NULL AND MONTH(measure_start) = fy_month AND DAY(measure_start) < fy_day
     THEN CONCAT(YEAR(measure_start) - 1, '' - '', YEAR(measure_start)) END) AS ''Year '',
  amount                                                                     AS amount,
  cost                                                                       AS cost
FROM data_operations
  LEFT JOIN data_measure ON data_operations.measure = data_measure.id
  INNER JOIN profile_locationmeta ON data_operations.loc_id = profile_locationmeta.loc_id
WHERE data_operations.id IN (SELECT MAX(id)
                             FROM data_operations
                             GROUP BY parent_id)

1 个答案:

答案 0 :(得分:1)

使用htmlspecialchars在您的网站上回显它。
假设您的查询位于$ query变量内,那就是您打印它的方式

echo htmlspecialchars($query, ENT_QUOTES);