Best practice: Import mySQL file in PHP; split queries

后端 未结 13 620
Happy的楠姐
Happy的楠姐 2020-11-29 00:08

I have a situation where I have to update a web site on a shared hosting provider. The site has a CMS. Uploading the CMS\'s files is pretty straightforward using FTP.

<
13条回答
  •  孤城傲影
    2020-11-29 00:41

    I ran into the same problem. I solved it using a regular expression:

    function splitQueryText($query) {
        // the regex needs a trailing semicolon
        $query = trim($query);
    
        if (substr($query, -1) != ";")
            $query .= ";";
    
        // i spent 3 days figuring out this line
        preg_match_all("/(?>[^;']|(''|(?>'([^']|\\')*[^\\\]')))+;/ixU", $query, $matches, PREG_SET_ORDER);
    
        $querySplit = "";
    
        foreach ($matches as $match) {
            // get rid of the trailing semicolon
            $querySplit[] = substr($match[0], 0, -1);
        }
    
        return $querySplit;
    }
    
    $queryList = splitQueryText($inputText);
    
    foreach ($queryList as $query) {
        $result = mysql_query($query);
    }
    

提交回复
热议问题