Bitrix Site Manager


 string table,
 array fields,
 string dir = "",
 string site = false

The method PrepareInsert prepares an array of the two strings for issuing an SQL query used to insert a record in the database. The method converts all values to the SQL-compliant format with respect to the field type and handles file operations returning the ID from the file table.


table Name of the table to insert a record into.
fields Array of field values in the form of "field name1"=>"value1", "field name2"=>"value2" [, ...].
Use a value of false to insert NULL. To insert a file attached to a record, set a value to an array of the following format:
"name" => "file name",
"size" => "file size",
"tmp_name" => "temporary path and name on the server",
"type" => "file type",
"del" => "delete (Y) or not (N) the file",
"MODULE_ID" => "module name");
You can easily build such an array by combining arrays $HTTP_POST_FILES[field name] and Array("del" => ${"field_name"."_del"}, "MODULE_ID" = "module name");
dir Name of the folder to store files (the folder is created in the folder upload). Used for the inserting files attached to a record.
Optional; the default value is an empty string.
site Site ID (for public section) or the language ID (for administrative section). Used to determine the date format when inserting fields of the type date or datetime.
Optional; the current ID is used by default.

Return Values

Returns an array of the two elements. The element with the key "0" contains a list of fields in the form of "field_name1, field_name2[, ...]", while the element [1] contains a string "value1, value2[, ...]".

See Also


function AddResultAnswer($arFields)
    $err_mess = (CForm::err_mess())."<br>Function: AddResultAnswer<br>Line: ";
    global $DB;
    $arInsert = $DB->PrepareInsert("b_form_result_answer", $arFields, "form");
    $strSql = "INSERT INTO b_form_result_answer (".$arInsert[0].") VALUES (".$arInsert[1].")";
    $DB->Query($strSql, false, $err_mess.__LINE__);
    return intval($DB->LastID());