Say I have the following line (forget that this is a MySQL statement):
SELECT * FROM users WHERE name = 'fred bloggs' AND age=21 AND address='Mountain View, CA 94043' LIMIT 1
I need a way to extract the name and value of a field in a WHERE clause, so I have an array like:
Array
(
[name] => fred bloggs
[age] => 21
[address] => Mountain View, CA 94043
)
Remember, this is a dynamic MySQL string, so I cannot specify the name, age or address of the hard code.
I can anticipate the following problems:
- Searching for field names, the function must know all valid operators in order to match each field name (see the array that will be used below)
- Spaces are not guaranteed (e.g. age = 21)
- Finding values inside 'and' but not breaking when 'is inside a string
- Searching for values not within 'and', for example. numbers or other field names (will need to be processed separately)
- , ?
, :
$operators = array('+', '-', '*', '/', '^', '=', '<>', '!=', '<', '<=', '>', '>=', 'like', 'clike', 'slike', 'not', 'is', 'in', 'between', 'and', 'or');