Documentation

ParseSqlBatch

array
CDatabase::ParseSqlBatch(
 string sql,
 bool Incremental = False
)

The method parses the string containing a bundle of queries and creates an array of queries. Non-static method.

Parameters

ParameterDescription Available from version
sql String containing a packet of queries. Queries are separated with ";" for the MySQL version or "/" for the Oracle version.
Incremental Optional.

See Also

Examples of use

<?
function RunSqlBatch($filepath)
{
    $arErr = Array();
	// open 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;
}
?>


© «Bitrix24», 2001-2024
Up