Page 1 of 1

Need help in Php using Regular expression

Posted: Wed May 20, 2009 8:34 pm
by teapear
Hello guys..

i need your help to convert this sql statement to php array..

Code: Select all

 
$string = "SELECT
                 TOP 15
                    e.id,
                    e.title,
                    e.timestamp
 
                FROM
                    serendipity_entries AS e
                    LEFT JOIN serendipity_authors a
                        ON e.authorid = a.authorid
                    LEFT JOIN serendipity_entrycat ec
                        ON e.id = ec.entryid
                      LEFT JOIN serendipity_access AS acl_acc
                                   ON (    acl_acc.artifact_mode = 'read'
                                       AND acl_acc.artifact_type = 'category'
                                       AND acl_acc.artifact_id   = c.categoryid
                                      )
                    WHERE isdraft = 'false' AND e.timestamp <= 1242781500 AND     (
                                 c.categoryid IS NULL
                                 OR ( acl_acc.groupid = 0)
                                 OR ( acl_acc.artifact_id IS NULL
                                    )
                               )
                     GROUP BY e.id,e.title,e.timestamp
 
                     ORDER BY timestamp DESC"
 

TO php array

Code: Select all

 
 
Array
(
    [SELECT] => e.id, e.title, e.timestamp
   
    [TOP] => 15
    
    [FROM] => serendipity_entries AS e
                    LEFT JOIN serendipity_authors a
                        ON e.authorid = a.authorid
                    LEFT JOIN serendipity_entrycat ec
                        ON e.id = ec.entryid
                      LEFT JOIN serendipity_access AS acl_acc
                                   ON (    acl_acc.artifact_mode = 'read'
                                       AND acl_acc.artifact_type = 'category'
                                       AND acl_acc.artifact_id   = c.categoryid
                                      )
   
    [WHERE] =>  isdraft = 'false' AND e.timestamp <= 1242781500 AND     (
                                 c.categoryid IS NULL
                                 OR ( acl_acc.groupid = 0)
                                 OR ( acl_acc.artifact_id IS NULL
                                    )
                               )
    [GROUP BY] => e.id,e.title,e.timestamp
    [ORDER BY] => timestamp DESC
 
) 
 
 
 
Thanks... :D

Re: Need help in Php using Regular expression

Posted: Thu May 21, 2009 2:22 am
by prometheuzz
Parsing (programming) languages using regex is a nightmare, and in many cases not possible, or at least not with a regex that a normal human being can understand.
I suggest you give your favourite search engine the words "sql parser php" and see what it comes up with.