Nextcloud PHP API (stable18)

IDBConnection

Interface IDBConnection

Tags
since
6.0.0

Table of Contents

ADD_MISSING_INDEXES_EVENT  = self::class . '::ADD_MISSING_INDEXES'
CHECK_MISSING_INDEXES_EVENT  = self::class . '::CHECK_MISSING_INDEXES'
beginTransaction()  : mixed
Start a transaction
close()  : mixed
Close the database connection
commit()  : mixed
Commit the database changes done during a transaction that is in progress
connect()  : bool
Establishes the connection with the database.
createSchema()  : Schema
Create the schema of the connected database
dropTable()  : mixed
Drop a table from the database if it exists
errorCode()  : int
Fetch the SQLSTATE associated with the last database operation.
errorInfo()  : array
Fetch extended error information associated with the last database operation.
escapeLikeParameter()  : string
Escape a parameter to be used in a LIKE query
executeQuery()  : Statement
Executes an, optionally parameterized, SQL query.
executeUpdate()  : int
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.
getDatabasePlatform()  : AbstractPlatform
Gets the DatabasePlatform instance that provides all the metadata about the platform this driver connects to.
getError()  : string
Gets the error code and message as a string for logging
getQueryBuilder()  : IQueryBuilder
Gets the QueryBuilder for the connection.
insertIfNotExist()  : int
Insert a row if the matching row does not exists. To accomplish proper race condition avoidance it is needed that there is also a unique constraint on the values. Then this method will catch the exception and return 0.
insertIgnoreConflict()  : int
Insert a row if the row does not exist. Eventual conflicts during insert will be ignored.
inTransaction()  : bool
Check if a transaction is active
lastInsertId()  : int
Used to get the id of the just inserted element
lockTable()  : mixed
Create an exclusive read+write lock on a table
migrateToSchema()  : mixed
Migrate the database to the given schema
prepare()  : Statement
Used to abstract the ownCloud database access away
quote()  : string
Quotes a given input parameter.
rollBack()  : mixed
Rollback the database changes done during a transaction that is in progress
setValues()  : int
Insert or update a row value
supports4ByteText()  : bool
Check whether or not the current database support 4byte wide unicode
tableExists()  : bool
Check if a table exists
unlockTable()  : mixed
Release a previous acquired lock again

Constants

ADD_MISSING_INDEXES_EVENT

public mixed ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES'

CHECK_MISSING_INDEXES_EVENT

public mixed CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES'

Methods

beginTransaction()

Start a transaction

public beginTransaction() : mixed
Tags
since
6.0.0
Return values
mixed —

close()

Close the database connection

public close() : mixed
Tags
since
8.0.0
Return values
mixed —

commit()

Commit the database changes done during a transaction that is in progress

public commit() : mixed
Tags
since
6.0.0
Return values
mixed —

connect()

Establishes the connection with the database.

public connect() : bool
Tags
since
8.0.0
Return values
bool —

createSchema()

Create the schema of the connected database

public createSchema() : Schema
Tags
since
13.0.0
Return values
Schema —

dropTable()

Drop a table from the database if it exists

public dropTable(string $table) : mixed
Parameters
$table : string

table name without the prefix

Tags
since
8.0.0
Return values
mixed —

errorCode()

Fetch the SQLSTATE associated with the last database operation.

public errorCode() : int
Tags
since
8.0.0
Return values
int —

The last error code.

errorInfo()

Fetch extended error information associated with the last database operation.

public errorInfo() : array
Tags
since
8.0.0
Return values
array —

The last error information.

escapeLikeParameter()

Escape a parameter to be used in a LIKE query

public escapeLikeParameter(string $param) : string
Parameters
$param : string
Tags
since
9.0.0
Return values
string —

executeQuery()

Executes an, optionally parameterized, SQL query.

public executeQuery(string $query[, string[] $params = array() ][, array $types = array() ]) : Statement

If the query is parameterized, a prepared statement is used. If an SQLLogger is configured, the execution is logged.

Parameters
$query : string

The SQL query to execute.

$params : string[] = array()

The parameters to bind to the query, if any.

$types : array = array()

The types the previous parameters are in.

Tags
since
8.0.0
Return values
Statement —

The executed statement.

executeUpdate()

Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.

public executeUpdate(string $query[, array $params = array() ][, array $types = array() ]) : int

This method supports PDO binding types as well as DBAL mapping types.

Parameters
$query : string

The SQL query.

$params : array = array()

The query parameters.

$types : array = array()

The parameter types.

Tags
since
8.0.0
Return values
int —

The number of affected rows.

getDatabasePlatform()

Gets the DatabasePlatform instance that provides all the metadata about the platform this driver connects to.

public getDatabasePlatform() : AbstractPlatform
Tags
since
8.0.0
Return values
AbstractPlatform —

The database platform.

getError()

Gets the error code and message as a string for logging

public getError() : string
Tags
since
6.0.0
Return values
string —

insertIfNotExist()

Insert a row if the matching row does not exists. To accomplish proper race condition avoidance it is needed that there is also a unique constraint on the values. Then this method will catch the exception and return 0.

public insertIfNotExist(string $table, array $input[, array|null $compare = null ]) : int
Parameters
$table : string

The table name (will replace PREFIX with the actual prefix)

$input : array

data that should be inserted into the table (column name => value)

$compare : array|null = null

List of values that should be checked for "if not exists" If this is null or an empty array, all keys of $input will be compared Please note: text fields (clob) must not be used in the compare array

Tags
throws
DBALException
since
6.0.0
  • parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0
deprecated
15.0.0
Return values
int —

number of inserted rows

insertIgnoreConflict()

Insert a row if the row does not exist. Eventual conflicts during insert will be ignored.

public insertIgnoreConflict(string $table, array $values) : int

Implementation is not fully finished and should not be used!

Parameters
$table : string

The table name (will replace PREFIX with the actual prefix)

$values : array

data that should be inserted into the table (column name => value)

Tags
since
16.0.0
Return values
int —

number of inserted rows

inTransaction()

Check if a transaction is active

public inTransaction() : bool
Tags
since
8.2.0
Return values
bool —

lastInsertId()

Used to get the id of the just inserted element

public lastInsertId([string $table = null ]) : int
Parameters
$table : string = null

the name of the table where we inserted the item

Tags
since
6.0.0
Return values
int —

the id of the inserted element

lockTable()

Create an exclusive read+write lock on a table

public lockTable(string $tableName) : mixed

Important Note: Due to the nature how locks work on different DBs, it is only possible to lock one table at a time. You should also NOT start a transaction while holding a lock.

Parameters
$tableName : string
Tags
since
9.1.0
Return values
mixed —

migrateToSchema()

Migrate the database to the given schema

public migrateToSchema(Schema $toSchema) : mixed
Parameters
$toSchema : Schema
Tags
since
13.0.0
Return values
mixed —

prepare()

Used to abstract the ownCloud database access away

public prepare(string $sql[, int $limit = null ][, int $offset = null ]) : Statement
Parameters
$sql : string

the sql query with ? placeholder for params

$limit : int = null

the maximum number of rows

$offset : int = null

from which row we want to start

Tags
since
6.0.0
Return values
Statement —

The prepared statement.

quote()

Quotes a given input parameter.

public quote(mixed $input[, int $type = IQueryBuilder::PARAM_STR ]) : string
Parameters
$input : mixed

Parameter to be quoted.

$type : int = IQueryBuilder::PARAM_STR

Type of the parameter.

Tags
since
8.0.0
Return values
string —

The quoted parameter.

rollBack()

Rollback the database changes done during a transaction that is in progress

public rollBack() : mixed
Tags
since
6.0.0
Return values
mixed —

setValues()

Insert or update a row value

public setValues(string $table, array $keys, array $values[, array $updatePreconditionValues = [] ]) : int
Parameters
$table : string
$keys : array

(column name => value)

$values : array

(column name => value)

$updatePreconditionValues : array = []

ensure values match preconditions (column name => value)

Tags
throws
DBALException
throws
PreconditionNotMetException
since
9.0.0
Return values
int —

number of new rows

supports4ByteText()

Check whether or not the current database support 4byte wide unicode

public supports4ByteText() : bool
Tags
since
11.0.0
Return values
bool —

tableExists()

Check if a table exists

public tableExists(string $table) : bool
Parameters
$table : string

table name without the prefix

Tags
since
8.0.0
Return values
bool —

unlockTable()

Release a previous acquired lock again

public unlockTable() : mixed
Tags
since
9.1.0
Return values
mixed —

Search results