- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/mysql/database.php
- Класс: CDatabaseMysql
- Вызов: CDatabaseMysql::Insert
public function Insert($table, $arFields, $error_position = "", $DEBUG = false, $EXIST_ID = "", $ignore_errors = false)
{
if (!is_array($arFields))
{
return false;
}
$str1 = "";
$str2 = "";
foreach ($arFields as $field => $value)
{
$str1 .= ($str1 <> "" ? ", " : "") . $this->quote($field);
if ((string)$value == '')
{
$str2 .= ($str2 <> "" ? ", " : "") . "''";
}
else
{
$str2 .= ($str2 <> "" ? ", " : "") . $value;
}
}
if ($EXIST_ID <> '')
{
$strSql = "INSERT INTO " . $table . "(ID," . $str1 . ") VALUES ('" . $this->ForSql($EXIST_ID) . "'," . $str2 . ")";
}
else
{
$strSql = "INSERT INTO " . $table . "(" . $str1 . ") VALUES (" . $str2 . ")";
}
if ($DEBUG)
{
echo "
" . htmlspecialcharsEx($strSql) . "
";
}
$res = $this->Query($strSql, $ignore_errors, $error_position);
if ($res === false)
{
return false;
}
if ($EXIST_ID <> '')
{
return $EXIST_ID;
}
else
{
return $this->LastID();
}
}