Bitrix Site Manager

CDatabase::RunSqlBatch

mixed
CDatabase::RunSqlBatch(
 string path
)

The method RunSqlBatch method executes a set of queries contained in the file path.

Parameters

ParameterDescription
path File containing the batch of queries. The MySQL queries are separated with ";". The Oracle queries are separated with "/".

Return Values

Returns false is all queries are successfully processed. Otherwise, the method returns the array of errors descriptions each explaining the reason of failure for a specific query.

See Also

Example



<?
$arrErrors = $DB->RunSqlBatch($_SERVER["DOCUMENT_ROOT"].
"/bitrix/modules/form/install/db/".strtolower($DB->type)."/install.sql");
?>

Sample file with MySQL queries


create table if not exists b_stat_adv_searcher (
   ID int(11) not null auto_increment,  
   ADV_ID int(11) not null,  
   SEARCHER_ID int(11) not null,  
   primary key (ID));
insert  into b_stat_adv (ID, REFERER1, REFERER2) values (1, 'google', '') ;
insert  into b_stat_adv_searcher (ID, ADV_ID, SEARCHER_ID) values (1, 2, 4) ;

Sample file with Oracle queries


CREATE TABLE B_STAT_ADDITIONAL 
(
    ID         NUMBER(18)    NOT NULL,
    C_TYPE     VARCHAR2(255) NOT NULL,
    NAME       NUMBER(18)    NULL,
    SESSIONS   NUMBER(18)    DEFAULT 0 NOT NULL,
    HITS       NUMBER(18)    DEFAULT 0 NOT NULL,
    NEW_GUESTS NUMBER(18)    DEFAULT 0 NOT NULL,
    C_EVENTS   NUMBER(18)    DEFAULT 0 NOT NULL,
    PRIMARY KEY (ID)
)
/
CREATE SEQUENCE SQ_B_STAT_ADDITIONAL 
	START WITH 44 
	INCREMENT BY 1 
	NOMINVALUE 
	NOMAXVALUE 
	NOCYCLE 
	NOCACHE 
	NOORDER
/
INSERT INTO B_STAT_ADV (ID, REFERER1, REFERER2) VALUES (1, 'google', '')
/
DROP SEQUENCE SQ_B_STAT_ADV
/
CREATE SEQUENCE SQ_B_STAT_ADV 
	START WITH 8 
	INCREMENT BY 1 
	NOMINVALUE 
	NOMAXVALUE 
	NOCYCLE 
	NOCACHE 
	NOORDER
/
INSERT INTO B_STAT_ADV_SEARCHER (ID, ADV_ID, SEARCHER_ID) VALUES (1, 2, 4)
/