Update
int CDatabase::Upd ate( string table, array fields, string where = "", string error_position = "", bool debug = false, bool ignore_errors = false, string additional_check=true )
The method updates records in the table with the valued passed in fields. Returns the number of upd ated records. Non-static method.
Note: all field values must be prepared for SQL query, for example, via the CDatabase::ForSql method.
Parameters
Parameter | Description | Available fr om version |
---|---|---|
table | Table name. | |
fields | Array of field values in the "field"=>"value",... format | |
where | Limiting condition for WHERE in the SQL format Optional. All records in the table are upd ated by default. | |
error_position | String indicating the CDatabase::Update method call position in the code. If SQL query fails and the file /bitrix/php_interface/dbconn.php has the variable $DBDebug=true;, then this information and SQL query will be displayed on the screen. | |
debug | If se t to true, the method shows text of an SQL query.If se t to "true", the method shows text of an SQL query. | |
ignore_errors | Specifies to ignore errors. If se t to true, the method ignores any SQL errors and continues execution. Optional; false by default.. | |
additional_check | Optional. True by default. |
See Also
- CDatabase::Query
- [link= 6657908]CDatabase::ForSql[/link]
- CDatabase::Insert
- CDatabase::PrepareInsert
- CDatabase::PrepareUpdate
Examples of use
<? if (strlen($save)>0) { if (CheckFields()) { $DB->PrepareFields("b_form"); $arFields = array( "TIMESTAMP_X" => $DB->GetNowFunction(), "NAME" => "'".trim($str_NAME)."'", "VARNAME" => "'".trim($str_VARNAME)."'", "C_SORT" => "'".intval($str_C_SORT)."'", "FIRST_SITE_ID" => "'".$DB->ForSql($FIRST_SITE_ID,2)."'", "BUTTON" => "'".$str_BUTTON."'", "DESCRIPTION" => "'".$str_DESCRIPTION."'", "DESCRIPTION_TYPE" => "'".$str_DESCRIPTION_TYPE."'", "SHOW_TEMPLATE" => "'".trim($str_SHOW_TEMPLATE)."'", "MAIL_EVENT_TYPE" => "'".$DB->ForSql("FORM_FILLING_".$str_VARNAME,50)."'", "SHOW_RESULT_TEMPLATE" => "'".trim($str_SHOW_RESULT_TEMPLATE)."'", "PRINT_RESULT_TEMPLATE" => "'".trim($str_PRINT_RESULT_TEMPLATE)."'", "EDIT_RESULT_TEMPLATE" => "'".trim($str_EDIT_RESULT_TEMPLATE)."'", "FILTER_RESULT_TEMPLATE" => "'".trim($str_FILTER_RESULT_TEMPLATE)."'", "TABLE_RESULT_TEMPLATE" => "'".trim($str_TABLE_RESULT_TEMPLATE)."'", "STAT_EVENT1" => "'".trim($str_STAT_EVENT1)."'", "STAT_EVENT2" => "'".trim($str_STAT_EVENT2)."'", "STAT_EVENT3" => "'".trim($str_STAT_EVENT3)."'" ); $DB->StartTransaction(); if ($ID>0) { $DB->Update("b_form", $arFields, "WH ERE ID='".$ID."'", $err_mess.__LINE__); } else { $ID = $DB->Insert("b_form", $arFields, $err_mess.__LINE__); $new="Y"; } $ID = intval($ID); if (strlen($strError)<=0) { $DB->Commit(); if (strlen($save)>0) LocalRedirect("form_list.php?lang=".LANGUAGE_ID); elseif ($new=="Y") LocalRedirect("form_edit.php?lang=".LANGUAGE_ID."&ID=".$ID); } else $DB->Rollback(); } } ?>
© «Bitrix24», 2001-2024