Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Прямые запросы к базе данных

John edited this page Feb 20, 2017 · 1 revision
<?php
use Bitrix\Main\Application;
$connection = Application::getConnection();
$sqlHelper = $connection->getSqlHelper();
$sql = "SELECT ID FROM b_user WHERE LOGIN = '".$sqlHelper->forSql($login, 50)."'";
//$connection->query($sql, $limit);
//$connection->query($sql, $offset, $limit);
$recordset = $connection->query($sql);
while ($record = $recordset->fetch())
{
  //do something
}
//---------------
$recordset->addFetchDataModifier(
   function ($data)
   {
       $data["NAME"] .= "!";
       return $data;
   }
);
while ($record = $recordset->fetch(\Bitrix\Main\Text\Converter::getHtmlConverter()))
   {
      $data[] = $record;
   }
//------------
$cnt = $connection->queryScalar("SELECT COINT(ID) FROM table");
$connection->queryExecute("INSERT INTO table (NAME, SORT) VALUES ('Название', 100)")
Clone this wiki locally