Regex to get sql statement parts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • josh.23.french

    Regex to get sql statement parts

    Does anyone have a regex (or knows how to make one) that will get the
    parts of an sql statement?

    $sql = "SELECT (* or 'id, username, etc') FROM `(tablename)`, [WHERE
    `id` = 1 and `username` = ".$username ."][LIMIT (#)]"

    it should return the following array:

    $returnd_val = array(
    'fields'=>''(* or 'id, username, etc')",
    'table'=>"(tabl ename)",
    'where'=>"(`id` = 1 and `username` = \"joe user\")",
    'limit'=>"1"
    );

    A similar regex for update, delete, and insert would help too ;)

  • petersprc@gmail.com

    #2
    Re: Regex to get sql statement parts

    Try http://pear.php.net/package/SQL_Parser

    josh.23.french wrote:
    Does anyone have a regex (or knows how to make one) that will get the
    parts of an sql statement?
    >
    $sql = "SELECT (* or 'id, username, etc') FROM `(tablename)`, [WHERE
    `id` = 1 and `username` = ".$username ."][LIMIT (#)]"
    >
    it should return the following array:
    >
    $returnd_val = array(
    'fields'=>''(* or 'id, username, etc')",
    'table'=>"(tabl ename)",
    'where'=>"(`id` = 1 and `username` = \"joe user\")",
    'limit'=>"1"
    );
    >
    A similar regex for update, delete, and insert would help too ;)

    Comment

    • josh.23.french

      #3
      Re: Regex to get sql statement parts

      I can't use this package on my server... Any other ideas?

      Comment

      Working...