Documentation

CDatabase class

CDatabase handles databases.

When launching each page, a global $DB object of CDatabase class is created automatically. This object is specifically used to perform all actions with a database.

Class methods

Method Description Available from version
ForSql Converts strings to ins ert data into SQL query.
Query Executes a query.
QueryBind Executes SQL queries of "UPDATE", "INSERT" types, that have the necessity to bind variables (as a rule, for the fields of BLOB, CLOB, LONG type and etc.).
QueryBindSelect Executes SQL query of "SELECT" type, that have the necessity to bind variables.
Update Universal update for database (without field value preparation).
NextID Returns the next sequence value.
Insert Universal ins ert in to database (without field value preparation).
LastID Gets the ID of the last inserted record.
PrepareFields Initializes global variables to ins ert in to SQL query.
PrepareInsert Universal ins ert in to database (with field value preparation).
PrepareUpdate Universal update for database (without field value preparation).
InitTableVarsForEdit Initializes global variables for display.
ParseSqlBatch Parses a query batch for array.
RunSqlBatch Executes file with query batch.
StartTransaction Opens transaction.
Commit Commits the commenced transaction.
Rollback Rolls back transaction.
Connect Opens a connection to the database.
Disconnect Closes a previously opened connection to the database.

Data and time handling methods

Method Description Available from version
CurrentDateFunction Returns function used to get the current date.
CurrentTimeFunction Returns function of the current date-time.
CharToDateFunction Returns string used to ins ert the date into the database query.
DateToCharFunction Returns string to retrieve the date into the database query.
DateFormatToPHP Converts any date and time format allowed by the site settings to the PHP format (in the 'date' function).
FormatDate Converts the date from the source format in to another.
CompareDates Compares two dates.
IsDate Checks the data validity.
DatetimeToTimestampFunction Returns the valid timestamp without invoking to MakeTimeStamp.

Note When working with the database, time in GMT format is the minimum requirement. To depend less on the server settings, its better to use datetime. In this case, the current time val ue must be retrieved via PHP.

See Also



© «Bitrix24», 2001-2024
Up