简体   繁体   English

用PHP解释SQL

[英]Interpreting SQL with PHP

So, I need to use PHP to pull out field names and values from the where statement of a sql query, change them, then put the thing back together. 所以,我需要使用PHP从sql查询的where语句中提取字段名称和值,更改它们,然后将事物重新组合在一起。

So, say I'm given this string: field='value' AND field2<7 I need to recognize field and field2 as field names, then feed then through the function field() and put them back into the query. 所以,比方说我给了这个字符串: field='value' AND field2<7我需要将field和field2识别为字段名称,然后通过函数field()反馈并将它们放回查询中。 Same things with 'value' and 7, but feed them through a value() function. 与'value'和7相同的东西,但通过value()函数提供它们。 It would also help to know what field each value was associated with. 它还有助于了解每个值与哪个字段相关联。

Is there any way to do this that won't take a few thousand lines to code? 有没有办法做到这一点,不需要几千行代码?

I need it to work with a lot of different possible inputs, including things like: table.field BETWEEN 7 AND 10 or field<7 AND (field2=3 OR field3=4) 我需要它来处理许多不同的可能输入,包括: table.field BETWEEN 7 AND 10field<7 AND (field2=3 OR field3=4)

我已经使用了php-sql-parser项目,它是开源的,非常好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM