How to strip/delete all values from MySQL queries using PHP Regex?

如何使用PHP Regex删除/删除MySQL查询中的所有值?

Example:

例子:

original: SELECT id, abc FROM mytable WHERE id IN (12, 15)
striped: SELECT id, abc FROM mytable WHERE id IN ()

原始:从(12,15)中id所在的mytable中选择id, abc,从()中id所在的mytable中选择id,

original:

原:

SELECT ut.id, IF(stagiaire_devis.id IS NOT NULL, CONCAT(ut.prenom, ' (my lovely)', ut.prenom) AS value FROM quality AS uq, avocate, utility AS ut LEFT JOIN stagiaire_devis ON (stagiaire_devis.id_devis='1293049' AND stagiaire_devis.id_utilisateur=ut.id) WHERE uq.id_utilisateur = ut.id AND avocate.id_utilisateur = ut.id AND avocate.deleted = 0 AND avocate.id_avocat_liste_cabinet = 7 AND uq.id_liste_qualite IN (5,2,9) AND uq.actif = 2 ORDER BY ut.prenom

striped:

条纹:

SELECT ut.id, IF(stagiaire_devis.id IS NOT NULL, CONCAT(ut.prenom, '', ut.prenom) AS value FROM quality AS uq, avocate, utility AS ut LEFT JOIN stagiaire_devis ON (stagiaire_devis.id_devis='' AND stagiaire_devis.id_utilisateur=ut.id) WHERE uq.id_utilisateur = ut.id AND avocate.id_utilisateur = ut.id AND avocate.deleted = AND avocate.id_avocat_liste_cabinet = AND uq.id_liste_qualite IN () AND uq.actif = ORDER BY ut.prenom

I cannot find right regex :(

我找不到正确的regex:(

1 个解决方案

#1


3

You can't do this with any regex because SQL is not a regular language.

对于任何regex都不能这样做,因为SQL不是一种常规语言。

To do this task, you need to use an SQL parser.

要执行此任务,需要使用SQL解析器。


Edit regarding your comment:

编辑对你的评论:

Okay, you need to establish a kind of 'fingerprint' for the query so that you can group queries together when they differ only in constant values.

好的,您需要为查询建立一种“指纹”,以便您可以在查询仅在常量值上存在差异时将它们分组在一起。

The pt-query-digest tool can do this. It works with the slow-query log or the general log, but not the error log. But it's probably not hard to use awk or something to convert your error log into a format that pt-query-digest can read.

pt-query-digest工具可以这样做。它使用的是慢查询日志或普通日志,而不是错误日志。但是,使用awk或其他东西将错误日志转换为pt-query-digest可以读取的格式可能并不困难。

更多相关文章

  1. 在PHP中,为什么没有显示解析错误?
  2. php异常和错误处理
  3. APMServ 在 Win7 下出现“APMServ-Apache 服务因 函数不正确。
  4. 从。net调用Magento API,并得到“位于XYZ的HTTP服务太忙”的错误
  5. 我得到了“致命错误:未捕获的SoapFault异常:[客户机]SoapClient:
  6. 建站学习(PHP+apache+mysql):1.1 日志详解
  7. log4php将不同级别的日志打印到不同的日志文件中
  8. ajax php bomt头 utf-8带来的奇怪问题。。返回值false 判断也是f
  9. 编译php时遇到的错误

随机推荐

  1. Android相机Camera基础知识
  2. AndroidResource
  3. GridView控件的简单使用
  4. [android]Android异步处理系列文章索引
  5. Android 图表开源框架之MPAndroidChart L
  6. [Android] Android之Service案例-电话窃
  7. Android消息队列模型--Thread,Handler,Lo
  8. Android SDK Manager 更新
  9. 打包Android应用程序
  10. android 4.4 按键分析三