Documentation

PrepareInsert

array
CDatabase::PrepareInsert(
 string TableName,
 array fields,
 string FileDir = "",
 string lang = false
)

The method prepares array of two strings for SQL query that inserts a record to the database. Returns an array of two elements. The element with key '0' contains a list of fields in the form of "field_name1, field_name2[, ...]", while the element [1] contains a string "value1, value2[, ...]". The method converts all values to the SQL-compliant format with respect to the field type. Non-static method.

Parameters

ParameterDescription
TableNameName of the table to ins ert a record into.
fieldsArray of field values in the format of "field name1"=>"value1", "field name2"=>"value2" [, ...].
Use a val ue of false to insert NULL.
FileDirNot used.
langSite 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; false by default.

See Also

Examples of use

<?
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 = "INS ERT IN TO b_form_result_answer (".$arInsert[0].") VALUES (".$arInsert[1].")";
	$DB->Query($strSql, false, $err_mess.__LINE__);
	return intval($DB->LastID());
}
?>


© «Bitrix24», 2001-2024
Up