<?php
$str = "INSERT INTO `f_part` (lname,fname,email) VALUES ('tha','thia','thia@gmail.com')";
?>
anyone could help me to convert this string to be an array
$result = array('table'=>'f_part',
'data'=>array('lname=>'tha','fname=>'thia','email'=>'thia@gmail.com')
)
You need to analyze the query by looking for different MySQL keywords such as INSERT, SELECT, INTO, VALUES, FROM, WHERE, etc. However, this can get tricky and hard because you have to watch out to for single quotes, escape characters, etc.
I suggest you just use http://code.google.com/p/php-sql-parser/. The class already does the tricky parts. It’s not really the same as the output you want but it will provide you something similar, and even more.
Here is an example query:
And the sample output: