Bitrix Site Manager

CDatabase::ParseSqlBatch

array
CDatabase::ParseSqlBatch(
 string sql
)

The method ParseSqlBatch parses the string containing a bundle of queries and creates an array of queries.

Parameters

ParameterDescription
sql String containing a bundle of queries. Queries are separated with ";" for the MySQL version or "/" for the Oracle version.

Return Values

Array of queries.

See Also

Example



<?
function RunSqlBatch($filepath)
{
    $arErr = Array();
    // open a file with queries
    $f = @fopen($filepath, "rb");
    if($f)
    {
        $contents = fread($f, filesize($filepath));
        fclose($f);
        
        // split into separate queries
        $arSql = $this->ParseSqlBatch($contents);
        for($i=0; $i<count($arSql); $i++)
        {
            $strSql = str_replace("\r\n", "\n", $arSql[$i]);
            if(!$this->Query($strSql, true))
                $arErr[] = $this->db_Error;
        }
    }
    if(count($arErr)>0)
        return $arErr;

    return false;
}
?>