使用REGEX的块MySQL查询

时间:2018-03-19 17:36:44

标签: php mysql regex

我有Mysql查询

$query = "SELECT ticket_id, subject FROM tickets WHERE status_code = 0 GROUP BY priority ORDER BY incident_id LIMIT 5";

我想转换此

$select = "SELECT ticket_id, subject ";
$from = "FROM tickets ";
$where = " WHERE status_code = 0 ";
$group = "GROUP BY priority";
$order = "ORDER BY incident_id";
$limit = "LIMIT 5";
  

我怎样才能做到这一点?是否可以使用REGEX?请给   我的指示?

或建议我

  

如何使用REGEX获取特定的字符串值?

提前谢谢: - )

1 个答案:

答案 0 :(得分:1)

我建议使用PHP {s}解析器,例如https://github.com/greenlion/PHP-SQL-Parser

浏览他们的文档,您将找到如何完全按照您的要求完成上述操作的示例。 [编辑]:这是他们的手册页:https://github.com/greenlion/PHP-SQL-Parser/wiki/Parser-Manual

正则表达式解决方案会很快变得混乱......